簡體   English   中英

從 IdentityServer4 注銷時撤銷刷新令牌

[英]Revoke refresh tokens when signing out from IdentityServer4

這是我的自定義注銷端點:

[HttpPost("logout")]
public async Task<IActionResult> LogoutAsync()
{
    await _interaction.RevokeTokensForCurrentSessionAsync();
    await HttpContext.SignOutAsync();
    return Ok();
}

它刪除了 IdentityServer cookies 但如果此時用戶有一個 refresh_token 他仍然可以在注銷后使用它。 如何撤銷所有相關的刷新令牌? 我嘗試使用IIdentityServerInteractionService.RevokeTokensForCurrentSessionAsync但它不像預期的那樣工作。

你的客戶是SPA嗎? 如果是,請在注銷操作時從 localstorage 中刪除 refresh_token。

此外,您可以使用 HttpClient 在自定義注銷 function 中向此端點發出 POST 請求:

https://[Your_IdentityServer4_url]/connect/revocation
    token_type_hint=refresh_token
    client_id=[your_client_id]
    client_secret=[your_client_secret]
    token=[your_refresh_token]

或者,您可以像這樣在注銷時使用事件來撤銷刷新令牌。

.AddCookie("cookie", options =>
    {
        options.Cookie.Name = "mvccode";

        options.Events.OnSigningOut = async e =>
        {
            // revoke refresh token on sign-out
            await e.HttpContext.RevokeUserRefreshTokenAsync();
        };
    })

鏈接到文檔 - 這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM