我已经按照本教程中实现ASP.NET身份验证和OAuth授权:http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/
的OAuth的理解存储令牌
它目前的工作,但我不完全理解令牌,它的计时器的存储位置。
这是生成令牌代码:
public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
{
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
using (AuthRepository _repo = new AuthRepository())
{
IdentityUser user = await _repo.FindUser(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim("sub", context.UserName));
identity.AddClaim(new Claim("role", "user"));
context.Validated(identity);
}
}
我猜想,令牌存储在ASP.NET身份DB或托管的Web API应用程序中,但我不完全理解。
令牌存储在应用程序的内存中。它不会默认存储在任何地方。您应该查看IdentityServer实现,以获得更强大的oauth令牌提供程序。 – Yousuf