简体   繁体   English

使用带有 IdentityModel 4.1.1 的刷新令牌请求访问令牌

[英]Request Access Token using refresh token with IdentityModel 4.1.1

I am using IdentityModel 4.1.1 for OAuth2.0 Now here I stucked during create instance of TokenClient, which is used to request new access token using refresh token.我将 IdentityModel 4.1.1 用于 OAuth2.0 现在在这里我在创建 TokenClient 实例期间卡住,该实例用于使用刷新令牌请求新的访问令牌。

Here's the my code what I am doing,这是我正在做的代码,

TokenClientOptions clientOptions = new TokenClientOptions();
clientOptions.ClientId = _configDetails.Where(x => x.Key == "ClientId").Select(x => x.Value).FirstOrDefault().ToString();
clientOptions.ClientSecret = _configDetails.Where(x => x.Key == "ClientSecret").Select(x => x.Value).FirstOrDefault().ToString();

//Create token client object object
var tokenClient = new TokenClient("?",clientOptions); //Here I need help what I have to pass as first parameter?


TokenResponse refereshtokenCallResponse = await tokenClient.RequestRefreshTokenAsync(token.RefreshToken);

Below TokenClient Class provided by IdentityModel4.1.1 pkg,在 IdentityModel4.1.1 pkg 提供的 TokenClient 类下面,

public class TokenClient
{
    public TokenClient(HttpMessageInvoker client, TokenClientOptions options);
    public TokenClient(Func<HttpMessageInvoker> client, TokenClientOptions options);

    public Task<TokenResponse> RequestAuthorizationCodeTokenAsync(string code, string redirectUri, string codeVerifier = null, IDictionary<string, string> parameters = null, CancellationToken cancellationToken = default(CancellationToken));
    public Task<TokenResponse> RequestClientCredentialsTokenAsync(string scope = null, IDictionary<string, string> parameters = null, CancellationToken cancellationToken = default(CancellationToken));
    public Task<TokenResponse> RequestDeviceTokenAsync(string deviceCode, IDictionary<string, string> parameters = null, CancellationToken cancellationToken = default(CancellationToken));
    public Task<TokenResponse> RequestPasswordTokenAsync(string userName, string password = null, string scope = null, IDictionary<string, string> parameters = null, CancellationToken cancellationToken = default(CancellationToken));
    public Task<TokenResponse> RequestRefreshTokenAsync(string refreshToken, string scope = null, IDictionary<string, string> parameters = null, CancellationToken cancellationToken = default(CancellationToken));
    public Task<TokenResponse> RequestTokenAsync(string grantType, IDictionary<string, string> parameters = null, CancellationToken cancellationToken = default(CancellationToken));
}

As above class represent need to pass HttpMessageInvoker as first parameter, but I fully blanked about it.上面的类表示需要将 HttpMessageInvoker 作为第一个参数传递,但我对此完全空白。 I also referred IdentityModel document , but didn't get any clue我也提到了 IdentityModel文档,但没有得到任何线索

You have to pass as an argument an HttpClient, with an already set up BaseUrl.您必须将 HttpClient 作为参数传递,并且已经设置了 BaseUrl。

Take a look at the tests from GitHub , to see how it is constructed.看看来自GitHub的测试,看看它是如何构建的。

Edit: To clear up any confusion, HttpClient has HttpMessageInvoker as a base class.编辑:为了消除任何混淆, HttpClient将 HttpMessageInvoker 作为基类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM