Fork me on GitHub

IdentityServer4 退出登录后,跳转到原来页面

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",
    //...
};
posted @ 2017-05-13 17:31  田园里的蟋蟀  阅读(3256)  评论(8编辑  收藏  举报