【问题标题】:How to get new refresh token - Identity Server 4如何获取新的刷新令牌 - Identity Server 4
【发布时间】:2020-11-12 08:54:19
【问题描述】:

我目前正在制作 WPF 应用程序,并且正在使用 Identity Server 4 进行身份验证。现在我已经完成了所有工作,以便用户在旧令牌过期时使用刷新令牌获得新令牌:

            //request new token
            using (var newAccessTokenClient = new HttpClient())
            {
                var newAccessTokenResponse = await newAccessTokenClient.RequestRefreshTokenAsync(new RefreshTokenRequest
                {
                    Address = App.Current.Properties["IdentityServerAPIAddress"].ToString() + "connect/token",

                    ClientId = "wpf",
                    ClientSecret = "secret",
                    GrantType = "refresh_token",
                    Scope = "openid offline_access WebAPI",

                    RefreshToken = ReadRefreshToken()
                });

                if (newAccessTokenResponse.IsError)
                {
                    throw new Exception(newAccessTokenResponse.Exception.ToString());
                }
                else
                {
                    //refresh token was success, write new tokens
                    WriteTokens(newAccessTokenResponse.AccessToken, newAccessTokenResponse.RefreshToken);
                    App.Current.Properties["AccessToken"] = newAccessTokenResponse.AccessToken;
                }
            }

问题是每当它再次发生时,Identity Server 4 API 都会抱怨刷新令牌已被使用。如何获取新的刷新令牌?

我看过这个关于我可以实现的接口的文档,但我不知道如何使用它。

感谢任何帮助。谢谢。

【问题讨论】:

    标签: token identityserver4 access-token refresh-token


    【解决方案1】:

    当您使用刷新令牌请求新的访问令牌时,您应该在同一响应中取回新的刷新令牌。请检查 Fiddler 中的请求。

    您还可以使用此客户端设置控制 IdentityServer 如何处理刷新令牌:

                RefreshTokenUsage = TokenUsage.OneTimeOnly,
    

    【讨论】:

    • 你说得对,我相信。我不确定最初是什么引发了我使用相同令牌的错误。
    猜你喜欢
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 2020-01-08
    • 2019-05-02
    • 2014-04-08
    • 2021-08-25
    • 2014-09-18
    相关资源
    最近更新 更多