IdentityModel v.4.3.0 中的 RequestResourceOwnerPasswordAsync 被什么取代了?

use*_*160 5 asp.net-web-api asp.net-core identityserver4 identitymodel

我正在尝试获取资源所有者信息,但 RequestResourceOwnerPasswordAsync 方法在 v4.3.0 的 TokenClient 类中不可用。我搜索了文档,但没有找到此方法的替代方法。以下是我的代码:

在此输入图像描述

小智 6

您可以使用RequestPasswordTokenAsync使用密码授予类型发送令牌请求。

我相信推荐的方法是使用 HttpClientFactory:

//private readonly IHttpClientFactory _httpClientFactory;

var client = _httpClientFactory.CreateClient();
var disco = await client.GetDiscoveryDocumentAsync("http://localhost:5000");

if (disco.IsError) throw new Exception(disco.Error);

var tokenClient = _httpClientFactory.CreateClient();

var tokenResult = tokenClient.RequestPasswordTokenAsync(new PasswordTokenRequest
    {
        Address = disco.TokenEndpoint,
        ClientId = "ro.client",
        ClientSecret = "secret",
        UserName = "alice",
        Password = "alice"
    });
Run Code Online (Sandbox Code Playgroud)