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",
    //...
};


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM