[英]Request Access Token using refresh token with IdentityModel 4.1.1
我將 IdentityModel 4.1.1 用於 OAuth2.0 現在在這里我在創建 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文檔,但沒有得到任何線索
您必須將 HttpClient 作為參數傳遞,並且已經設置了 BaseUrl。
看看來自GitHub的測試,看看它是如何構建的。
編輯:為了消除任何混淆, HttpClient將 HttpMessageInvoker 作為基類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.