【发布时间】:2014-05-01 16:55:57
【问题描述】:
我想知道这是我的失败还是 ASP.NET Identity 的错误/功能。
我们在 ASP.NET MVC 5 项目中使用 ASP.NET Identity 1.0。 OAuth 的配置如下:
public partial class Startup
{
static Startup()
{
PublicClientId = "self";
UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/token"),
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
RefreshTokenProvider = new AuthenticationTokenProvider()
{
OnCreate = CreateRefreshToken,
OnReceive = ReceiveRefreshToken
},
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
}
public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
public static Func<SphUserManager> UserManagerFactory { get; set; }
public static string PublicClientId { get; private set; }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}
private static void CreateRefreshToken(AuthenticationTokenCreateContext context)
{
context.SetToken(context.SerializeTicket());
}
private static void ReceiveRefreshToken(AuthenticationTokenReceiveContext context)
{
context.DeserializeTicket(context.Token);
}
}
我们使用 Web API 来注册和登录用户。刷新令牌用于刷新访问令牌。这是我们没有预料到的:
- 注册用户
- 登录用户并获取访问令牌和刷新令牌(/token、grant_type=password...)
- 删除用户(直接从数据库或管理中)。
- 调用刷新令牌,请求不会失败。访问令牌被延长,用户仍然通过身份验证(/token、grant_type=refresh_token...)
这是正确的行为吗?我应该做一些特别的事情来“使”令牌“无效”吗?
【问题讨论】:
标签: asp.net-mvc asp.net-identity