gpt4 book ai didi

c# - 使用带有 IdentityModel 4.1.1 的刷新 token 请求访问 token

转载 作者:行者123 更新时间:2023-12-04 14:16:18 26 4
gpt4 key购买 nike

我将 IdentityModel 4.1.1 用于 OAuth2.0
现在在这里我在 TokenClient 的创建实例期间卡住了,该实例用于使用刷新 token 请求新的访问 token 。

这是我正在做的代码,

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 ,但没有得到任何线索

最佳答案

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

查看来自 GitHub 的测试,看看它是如何构建的。

编辑:为了消除任何混淆,HttpClient以 HttpMessageInvoker 作为基类。

关于c# - 使用带有 IdentityModel 4.1.1 的刷新 token 请求访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59961179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com