title: How can I Save GrantResourceOwnerCredentials methods return token value to database
body: <p>I am trying to implement Oauth by using Owin.  As Shown below I want to store  genereted Token in my Database.  I don't know how / where to take token value . Can I handle it in GrantResourceOwnerCredentials method or is there  any other method to override ? </p>
  
  <pre><code>  public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
      {
  
          context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
  
  
          using (EvdekiHesapContext _repo = new EvdekiHesapContext())
          {
              User user = null;
              try
              {
                  user = _repo.Users.Where(x =&gt; x.UserName == context.UserName &amp;&amp; x.PassWord == context.Password).FirstOrDefault();
              }
              catch (Exception ex)
              {
  
                  throw;
              }
  
  
              if (user != null)
              {
                  var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                  identity.AddClaim(new Claim("UserName", user.UserName));
                  identity.AddClaim(new Claim("role", "user"));
  
                  var ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
                  context.Validated(ticket);
                  // user.Token = ???  At this point , I want to save the genereted token to the DB. ??
                  _repo.SaveChanges();
              }
              else
              {
                  context.SetError("invalid_grant", "The user name or password is incorrect.");
                  return;
              }
          }
  
      }
  </code></pre>
  
  <p>Thanks.</p>