[英]IdentityModel RequestRefreshTokenAsync method always return invalid_client
I have the following code:我有以下代码:
public async Task<TokenResponse> RefreshTokenAsync(string refreshToken)
{
HttpClient client = new();
var discoveryResponse = await client.GetDiscoveryDocumentAsync("https://localhost:44334");
var response = await client.RequestRefreshTokenAsync(new RefreshTokenRequest
{
Address = discoveryResponse.TokenEndpoint,
ClientId = "...",
ClientSecret = "...",
RefreshToken = refreshToken
});
return response;
}
And it always returns 400 Bad Request with invalid_client message.它总是返回带有 invalid_client 消息的 400 Bad Request。 When I'm refreshing token in Postman it works well.
当我在 Postman 中刷新令牌时,它运行良好。 Where is the problem?
问题出在哪儿?
The purpose of the refresh-token is: the user does not need to re-authenticate with the credentials (username/password) in the application every time the session expires. refresh-token的作用是:用户不需要在每次session过期的时候,用应用中的凭据(用户名/密码)重新认证。 So your application needs to connect to the endpoint identity and consume a new refresh token before the token or refresh token times out.
因此,您的应用程序需要连接到端点身份并在令牌或刷新令牌超时之前使用新的刷新令牌。 In asp do.net core Identity and JwtToken always have a default timeout value;
在 asp do.net core 中,Identity 和 JwtToken 总是有一个默认的超时值; whatever: you need to capture the refresh token before this timeout expires, otherwise your identity understands the user who does not have the browser open or is not online.
不管怎样:您需要在此超时到期之前捕获刷新令牌,否则您的身份会理解没有打开浏览器或不在线的用户。 This may imply developing a routine that stays in Roudin-Robin always refreshing the application with the new Token while the browser is open.
这可能意味着开发一个保留在 Roudin-Robin 中的例程,在浏览器打开时始终使用新令牌刷新应用程序。
I changed my code to this:我将代码更改为:
public async Task<TokenResponse> RefreshTokenAsync(string refreshToken)
{
HttpClient client = new();
var discoveryResponse = await client.GetDiscoveryDocumentAsync("https://localhost:44334");
var tokenClient = new TokenClient(client, new TokenClientOptions
{
Address = discoveryResponse.TokenEndpoint,
ClientId = "...",
ClientSecret = "...",
});
var response = await tokenClient.RequestRefreshTokenAsync(refreshToken);
response.HttpResponse.EnsureSuccessStatusCode();
return response;
}
And now it works as expected.现在它按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.