我正在使用IdentityModel.AspNetCore
客户端凭据流访问受保护的 api。在我的启动中,我在下面进行了配置。
services.AddAccessTokenManagement(options =>
{
options.Client.Clients.Add("oauth", new ClientCredentialsTokenRequest
{
Address = Configuration.GetValue<string>("Endpoint"),
ClientId = Configuration.GetValue<string>("ClientId"),
ClientSecret = Configuration.GetValue<string>("ClientSecret"),
Scope = Configuration.GetValue<string>("Scope")
});
});
services.AddClientAccessTokenClient("client", configureClient: client =>
{
client.BaseAddress = new Uri(Configuration.GetValue<string>("ApiBaseUrl"));
});
在我的服务中,我正在使用一个客户端实例IHttpClientFactory
var client = clientFactory.CreateClient("client");
这段代码运行良好,我可以访问 API。我的问题是,当我扩展从 clientFactory 获得的客户端实例时,其中的 Authorization 标头为空。所以我很困惑这是如何工作的。我预计它将使用不记名令牌详细信息设置授权标头值。那么这是如何工作的呢?IdentityModel 如何设置不记名令牌?(API 正确授权,好像我更改了客户端密码,它会给出 401)