简体   繁体   English

当用户密码更改时,IdentityServer会话和访问令牌无效

[英]Invalidating IdentityServer session and access token when a user's password changes

I'm using IdentityServer4 in ASP.NET Core 2.2. 我在ASP.NET Core 2.2中使用IdentityServer4。 The client application (RP) is an API, also an ASP.NET Core 2.2 application. 客户端应用程序(RP)是一个API,也是一个ASP.NET Core 2.2应用程序。 The user logs in using the authorization code flow and gets a cookie from IdentityServer ( idsrv ). 用户使用授权代码流登录并从IdentityServer( idsrv )获取cookie。 They then get an authorization code and and access token for the API (RP). 然后,他们获得API(RP)的授权代码和访问令牌。

I want to be able to revoke a user's existing login session and access tokens in some cases, eg if their password has been reset. 我希望能够撤销用户现有的登录会话并在某些情况下访问令牌,例如,如果他们的密码已被重置。 In IdentityServer I've implemented added my own authentication scheme: 在IdentityServer中,我实现了添加自己的身份验证方案:

            .AddCookie("MyAuthenticationScheme", options =>
            {
                options.SessionStore = new MyTicketStore();
                options.EventsType = typeof(MyCookieAuthenticationEvents);
            })

This allows me to invalidate the user's IdentityServer session on the server before the authentication ticket expires. 这允许我在身份验证票证到期之前使服务器上的用户IdentityServer会话无效。 For example, when the user is signed in I add a claim that stores the date their password was last changed and in MyCookieAuthenticationEvents.ValidatePrincipal() I check that it has not been changed since, as suggested on https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-2.2#react-to-back-end-changes 例如,当用户登录时,我添加一个声明,存储他们的密码最后更改的日期,并在MyCookieAuthenticationEvents.ValidatePrincipal()检查它是否已经更改,因为,如https://docs.microsoft所示。 COM / EN-US / ASPNET /核心/安全/认证/饼干吗?查看= aspnetcore-2.2#反应到后端,变化

I want to do the same with the access token they use the access the RP. 我想对他们使用访问RP的访问令牌做同样的事情。 If the user's password has changed (and in some other cases) I want the access token to be invalidated immediately, rather than waiting for it to expire. 如果用户的密码已更改(在某些其他情况下),我希望访问令牌立即失效,而不是等待它过期。 I'm using reference tokens and have implemented IProfileService and ICustomTokenValidator . 我正在使用引用标记并已实现IProfileServiceICustomTokenValidator In IProfileService.GetProfileDataAsync I copy the password change date claim to the access token claims collection and in ICustomTokenValidator.ValidateAccessTokenAsync I again check that claim against the real user. IProfileService.GetProfileDataAsync我将密码更改日期声明复制到访问令牌声明集合,并在ICustomTokenValidator.ValidateAccessTokenAsync再次检查对真实用户的声明。

This works, but it seems quite convoluted and complicated and I wonder if there is a simpler way to accomplish this - it seems like this should be a common requirement. 这是有效的,但它似乎相当复杂和复杂,我想知道是否有一个更简单的方法来实现这一点 - 似乎这应该是一个共同的要求。

如果您正在使用引用令牌,那么为了使令牌无效,您需要的只是将其从您拥有的IPersistedGrantStore任何实现中删除,并且下次尝试通过内省验证引用令牌时,它将无效,因为它将不会更长的存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用访问令牌 + OAuth 提供程序处理用户 session - Handle user session with access token + OAuth provider 令牌刷新时向 IdentityServer 发送自定义参数 - Send custom parameter to IdentityServer when token refreshing 身份令牌不调用 IdentityServer4 GetProfileDataAsync,只调用访问令牌 - IdentityServer4 GetProfileDataAsync is not called for Identity Token, only Access Token 无效的 Session 未注销 - Laravel 5 - Invalidating Session not logging out - Laravel 5 使客户端JWT会话无效 - Invalidating client side JWT session 无法使用IdentityServer4验证API中的JWT或access_token - Unable to Validate JWT or access_token in API with IdentityServer4 如何从JavaScript请求IdentityServer3客户端访问令牌? - How to request IdentityServer3 client access token from JavaScript? 在 MVC 客户端(IdentityServer)中自动获取 access_token - Automatically get access_token in MVC client (IdentityServer) IdentityServer3-通过混合流发布访问令牌的请求? - IdentityServer3 - post request for access token with hybrid flow? 使用外部身份验证提供程序获取用户凭据,使用私有IdentityServer生成令牌 - Use of external authentication provider for user credentials, private IdentityServer for token generation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM