IdentityServer настроен для хранения эталонных токенов в Sql Server.[A2]
Во время входа в систему IdentityServer создает два эталонных токена.[A3]
Во время выхода из системы и отзыва токена удаляется только один из этих токенов.[A4]
Почему IdentityServer создает два эталонных токена?
Мой клиент использует гибридный поток.[A1]
[A1]
services
.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddOpenIdConnect(options =>
{
var openIdConnectOptions = Configuration.GetSection("Authentication:OpenIdConnectOptions")
.Get<OpenIdConnectOptions>();
var scopes = Configuration.GetSection("Authentication:OpenIdConnectOptions:Scopes").Value;
options.Authority = openIdConnectOptions.Authority;
options.ClientId = openIdConnectOptions.ClientId;
options.ClientSecret = openIdConnectOptions.ClientSecret;
options.ResponseType = openIdConnectOptions.ResponseType;
options.SaveTokens = openIdConnectOptions.SaveTokens;
options.Scope.Add(scopes);
var redirectHost = (string) Configuration["Authentication:RedirectHost"];
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = context =>
{
if (!string.IsNullOrWhiteSpace(redirectHost))
{
context.ProtocolMessage.RedirectUri =
redirectHost + new Uri(context.ProtocolMessage.RedirectUri).PathAndQuery;
}
return Task.FromResult(0);
},
OnTokenResponseReceived = context =>
{
context.HttpContext.Response.Cookies.Append(
"id_token"
, context.TokenEndpointResponse.IdToken
, new CookieOptions
{
HttpOnly = true,
Secure = true
});
context.HttpContext.Response.Cookies.Append(
"access_token",
context.TokenEndpointResponse.AccessToken,
new CookieOptions
{
HttpOnly = true,
Secure = true
});
return Task.FromResult(0);
},
OnRedirectToIdentityProviderForSignOut = context =>
{
context.ProtocolMessage.PostLogoutRedirectUri = null;
var idToken = context.HttpContext.Request.Cookies["id_token"];
if (!string.IsNullOrEmpty(idToken))
{
context.ProtocolMessage.IdTokenHint = idToken;
}
return Task.FromResult(0);
},
OnRemoteFailure = context =>
{
var SigninOidc = "signin-oidc";
var uri = context.Request.GetUri().ToString();
if (uri.EndsWith(SigninOidc))
{
var redirectUri = "/";
context.Response.Redirect(redirectUri);
context.HandleResponse();
}
return Task.FromResult(0);
}
};
});
[A2]
factory.RegisterOperationalServices(efConfig);
[A3] [
] 1
[A4]
public void Logout()
{
HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme).GetAwaiter().GetResult();
HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme).GetAwaiter().GetResult(); ;
var token = Request.Cookies["access_token"];
var tokenClient = new TokenRevocationClient(
$"{_authenticationConfiguration.Authority}/connect/revocation",
_authenticationConfiguration.ClientId,
_authenticationConfiguration.ClientSecret);
var tokenResponse = tokenClient.RevokeAccessTokenAsync(token).GetAwaiter().GetResult();
}