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

时间:2020-01-29 05:51:47

标签: c# asp.net-mvc identitymodel

我正在为OAuth2.0使用IdentityModel 4.1.1 现在在这里,我在TokenClient的创建实例期间遇到了麻烦,该实例用于使用刷新令牌请求新的访问令牌。

这是我正在执行的代码,

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);

在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));
}

上述类表示需要将HttpMessageInvoker作为第一个参数传递,但是我对此完全空白。 我还提到了IdentityModel document,但没有任何线索

1 个答案:

答案 0 :(得分:2)

您必须将已经设置了BaseUrl的HttpClient作为参数传递。

看看GitHub中的测试,以了解其构造。

编辑:为消除任何混乱,HttpClient将HttpMessageInvoker作为基类。