CookieAuthenticationEvents.ValidatePrincipal revocation of refresh tokens #330
-
I want to add some extra validation on the cookie authentication for the authorize endpoint: when certain conditions are met I want to logout the user from the IdentityServer. To achieve this, I can implement public class CookieEventHandler : CookieAuthenticationEvents
{
public override async Task ValidatePrincipal(CookieValidatePrincipalContext context)
{
if (context.Principal.IsAuthenticated() && context.Request.Path == $"/{IdentityServerConstants.ProtocolRoutePaths.Authorize}")
{
if (CheckCondition())
{
context.RejectPrincipal();
await context.HttpContext.SignOutAsync();
}
}
}
private bool CheckCondition()
{
throw new NotImplementedException();
}
} This will actually logout the user but the refresh tokens associated with the session are not revoked and are still in the database, however I enabled the CoordinateClientLifetimesWithUserSession on IdentityServer level. I tried to understand how it works:
But I think the Is my analysis correct and how can I ensure the refresh tokens are revoked? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Since you're calling We're wondering what the use case is behind what you're trying to achieve, because there may be better suited places to check the specific condition and rejecting the user or access to the /authorize endpoint. One specific way would be to implement a custom authorize request validator, where you can reject the authorize request based on your conditions, and still decide to call We also have an |
Beta Was this translation helpful? Give feedback.
Since you're calling
context.RejectPrincipal();
in theValidatePrincipal
method, the end result of the underlyingAuthenticateAsync
call will have noClaimsPrincipal
available when the current user is being retrieved from theIUserSession
service.We're wondering what the use case is behind what you're trying to achieve, because there may be better suited places to check the specific condition and rejecting the user or access to the /authorize endpoint.
One specific way would be to implement a custom authorize request validator, where you can reject the authorize request based on your conditions, and still decide to call
SignOutAsync
when necessary.We also have an
IProfileService
which e…