在我的 Blazor 应用中,我使用身份服务器 (identityserver.io) 作为外部服务来管理授权。
登录工作正常,但是当我尝试注销,然后尝试登录时,我直接登录,而不询问任何用户名/密码!我已经搜索了一个星期了,但没有找到任何解决方案!
我使用以下代码:
var props = (returnUrl is null) ? null : new AuthenticationProperties()
{
RedirectUri = returnUrl
};
await HttpContext.SignOutAsync("Cookies");
await HttpContext.SignOutAsync("oidc", props);
我也尝试删除所有cookie,但HttpContext.Request.Cookies没有cookie!
我还检查了以下链接: https://mcguirev10.com/2018/01/26/signoutasync-and-identity-server-cookies.html 但我没有看到任何有帮助的!
仅供引用,这是我的设置方法:
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options =>
{
options.ExpireTimeSpan = TimeSpan.FromDays(365);
//options.Cookie.Name = ".MyApp";
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = true;
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.ClientId = configuration["AuthServer:ClientId"];
options.ClientSecret = configuration["AuthServer:ClientSecret"];
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("role");
options.Scope.Add("email");
options.Scope.Add("phone");
options.Scope.Add("MyApp");
options.ClaimActions.MapAbpClaimTypes();
});
}
最佳答案
要在从 IDS4 注销后通过单击链接Click here to return to the Interactive client ....
重定向回您的客户端应用程序,您应该在中设置正确的 PostLogoutRedirectUris
客户端配置:
new Client
{
....
// where to redirect to after logout
PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },
....
},
在@McGuireV10的文章中,他使用身份服务器的演示服务器进行测试,并使用interactive.confidential.short
客户端,您无法设置该客户端的PostLogoutRedirectUris
,因此默认为 https://localhost:5001/signout-callback-oidc
。您可以设置自己的身份服务器来测试场景。
关于c# - 网络核心/身份服务器: unable to logout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59486045/