IdentityModel2 TokenClient资源所有者密码

Gue*_*lla 2 c# identityserver4

我正在尝试使用IdentityModel2- https://github.com/IdentityModel/IdentityModel2获取持有人令牌

他们的github页面说它支持资源所有者密码

在此输入图像描述

但是我看不到任何添加用户名/密码的方法,也没有关于如何执行此操作的示例.

如何使用用户名和密码获取令牌TokenClient

Gue*_*lla 5

答案很简单,我错过了正确的方法.我将在这里添加而不是删除incase其他人偶然发现:

var client = new TokenClient(
    _identityEndpoints.TokenEndpoint,
    "client", "secret", AuthenticationStyle.PostValues);

var response = await client.RequestResourceOwnerPasswordAsync(user, pass, "scope");
var token = response.AccessToken;
Run Code Online (Sandbox Code Playgroud)