IdentityServer4 退出登录后,默认会跳转到Config.Client
配置的PostLogoutRedirectUris
地址,那我们如何动态的跳转到原来的地址呢?实现很简单,Logout
修改如下:
[HttpGet]
public async Task<IActionResult> Logout(string logoutId)
{
var logout = await _interaction.GetLogoutContextAsync(logoutId);
await HttpContext.Authentication.SignOutAsync();
if (logout.PostLogoutRedirectUri != null)
{
return Redirect(logout.PostLogoutRedirectUri);
}
var refererUrl = Request.Headers["Referer"].ToString();
return Redirect(refererUrl);
}
授权中心删除PostLogoutRedirectUris
配置:
new Client
{
ClientId = "h5",
//PostLogoutRedirectUris = { "http://localhost:5003/index.html" }
//...
}
前端项目删除post_logout_redirect_uri
配置:
var config = {
authority: "http://localhost:5001",
//post_logout_redirect_uri: "http://localhost:5003/index.html",
//...
};