【问题标题】:Refresh token doesn't fail after deleting the user删除用户后刷新令牌不会失败
【发布时间】: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 来注册和登录用户。刷新令牌用于刷新访问令牌。这是我们没有预料到的:

  1. 注册用户
  2. 登录用户并获取访问令牌和刷新令牌(/token、grant_type=password...)
  3. 删除用户(直接从数据库或管理中)。
  4. 调用刷新令牌,请求不会失败。访问令牌被延长,用户仍然通过身份验证(/token、grant_type=refresh_token...)

这是正确的行为吗?我应该做一些特别的事情来“使”令牌“无效”吗?

【问题讨论】:

    标签: asp.net-mvc asp.net-identity


    【解决方案1】:

    Katana OAuth2 中间件中的刷新令牌支持基本上取决于您,因此如果您删除用户,那么该逻辑也可以撤销(删除)该用户的所有刷新令牌。

    【讨论】:

    • 我会撤销刷新令牌,但它在客户端上。可以从 Web 应用程序(管理)中删除用户,并且与令牌没有任何联系。
    • 同样,如何实现刷新令牌取决于您——如果您希望在删除用户时刷新令牌无效,那么您需要进行此关联。
    • 我明白了。我希望它会更容易。感谢您的回复。
    • 我希望它也更容易。更多观点请参见:leastprivilege.com/2014/03/24/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多