CookieAuthenticationEvents.ValidatePrincipal token revocation after back-channel logout #243
-
|
Hi all! As mentioned in my previous post, we are considering implementing server-side sessions in our setup. After going through the samples (DuendeSamples/SessionManagement), lots of questions got spawned naturally. One of these is the "todo" comment from within the sample in public class CookieEventHandler : CookieAuthenticationEvents
{
public CookieEventHandler(LogoutSessionManager logoutSessions)
{
LogoutSessions = logoutSessions;
}
public LogoutSessionManager LogoutSessions { get; }
public override async Task ValidatePrincipal(CookieValidatePrincipalContext context)
{
if (context.Principal.Identity.IsAuthenticated)
{
var sub = context.Principal.FindFirst("sub")?.Value;
var sid = context.Principal.FindFirst("sid")?.Value;
if (LogoutSessions.IsLoggedOut(sub, sid))
{
context.RejectPrincipal();
await context.HttpContext.SignOutAsync();
// todo: if we have a refresh token, it should be revoked here.
}
}
}
}Can we talk about "if we have a refresh token, it should be revoked here" in the context of a setup that uses server-side sessions? Documentation suggests the following:
Do we still need to initiate refresh token revocation at this point from the client application, or is that taken care of by the coordination service within the IdentityServer? What about reference tokens (revokable access tokens)? Do I still need to initiate token revocation for the reference token? In my setup, I have a context.Result.ValidatedRequest.AccessTokenType = AccessTokenType.Reference;
var response = await generator.ProcessAsync(context.Result);
context.Result.CustomResponse = new Dictionary<string, object> { { ReferenceToken, response.AccessToken } };At the client, I'm saving it together with the JWT so I can access it via options.Events.OnTokenResponseReceived = context =>
{
if (context.TokenEndpointResponse.Parameters.TryGetValue("reference_token", out var referenceToken) is true
&& context.Properties is not null)
{
context.Properties.Items["reference_token"] = referenceToken;
}
return Task.CompletedTask;
};
options.Events.OnTicketReceived = context =>
{
if (context.Properties is not null)
{
var tokens = context.Properties.GetTokens().ToList();
if (context.Properties.Items.TryGetValue("reference_token", out var referenceToken)
&& !string.IsNullOrWhiteSpace(referenceToken))
{
tokens.Add(new() { Name = "reference_token", Value = referenceToken });
context.Properties.StoreTokens(tokens);
}
}
return Task.CompletedTask;
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
The Lifetime coordination can be enabled globally using the That said, revoking the refresh token manually from within the
|
Beta Was this translation helpful? Give feedback.
The persisted grant store can have some issues when querying or deleting a bunch of records because this table contains a lot of data. Sometimes, the operation can time out, or there could be a concurrency issue if multiple instances of IdentityServer attempt to update/remove the same records simultaneously.