identityserver4 - Authorization_Code SignOutAsyn() 不触发结束会话
问题描述
我有一个由 Identity Server 保护的门户,授权类型为
HttpContext.SignInAsync(ClaimsPrincipal)
工作正常并将用户重定向到门户,但是
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
在未触发 endsession 端点以将用户重定向到身份服务器下的注销操作的情况下,该方法不起作用
public async Task Logout()
{
await HttpContext.SignOutAsync
(CookieAuthenticationDefaults.AuthenticationScheme);
}
startup.cs
ConfigureService(IServiceCollection services)
services.AddAuthentication()
.AddCookie(cookieOptions =>
{
var tempProvider = services.BuildServiceProvider();
cookieOptions.Cookie.Name = "PortalAuth";
cookieOptions.Cookie.HttpOnly = true;
cookieOptions.SessionStore =
tempProvider.GetRequiredService<ITicketStore>();
configureCookieOptions?.Invoke(cookieOptions);
})
.AddIdentityServerAuthentication(
IdentityServerAuthenticationDefaults.AuthenticationScheme,
idServOptions =>
{
idServOptions.Authority =
options.AuthorizationServiceUrl;
idServOptions.RequireHttpsMetadata = false;
idServOptions.ApiName = options.ApplicationName;
idServOptions.ApiSecret = options.ApplicationSecret;
idServOptions.EnableCaching = true;
idServOptions.CacheDuration =
TimeSpan.FromMinutes(1);
idServOptions.SupportedTokens =
SupportedTokens.Reference;
configureIdentityServerOptions?.Invoke(idServOptions);
idServOptions.Validate();
});
var client = new Client{
...
RedirectUris = { "http://localhost:12345" },
PostLogoutRedirectUris = { "http://localhost:12345" },
}
我在设置中还缺少什么来触发结束会话端点。如果我需要手动调用 endsession 那么如何获取 id_token_hint 并且我正在使用 authentication_code 授权类型
var disco = await
DiscoveryClient.GetAsync(Constants.AuthorizationServiceUrl);
var endSessionUrl = new
RequestUrl(disco.EndSessionEndpoint)
.CreateEndSessionUrl(IdTokenHint:?,State:?);
return Redirect(endSessionUrl);
解决方案
推荐阅读
- android - 如何为包含 navHostFragment 的活动设置SoftInput?
- swiftui - SwiftUI 最佳实践:View 是否应该对单例有一个常量,它们是否应该在 Environment 中传递?
- python - python:如何插入闭合轮廓
- sql - 有条件地删除重复记录
- uinavigationbar - SwiftUI 隐藏导航栏影响其他动画
- python - 为什么 BeautifulSoup 无法在 Google 上获取所有 html?
- java - 如何使用一个 talend 作业根据 ftphost 名称连接到多个 ftp 站点
- php - PHP中的用户定义函数,变量有问题吗?
- python - 在 Google Colab Pro 中使用 TPU v3
- android - 避免使用 getIdentifier 检索文本资源的方法?