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