简体   繁体   English

为 .NET Core 3.1/IdentityModel 5.1 使用 ResourceOwnerPassword 流

[英]Using ResourceOwnerPassword flow for .NET Core 3.1/IdentityModel 5.1

I am playing with the IdentityServer4.我正在使用 IdentityServer4。 Part of that I am trying to build a client using IdentityModel 5.1.0 and trying to use following piece of code available here那我想建立使用IdentityModel 5.1.0客户端,并尝试使用下面的一段可用的代码部分在这里

// request token
var tokenClient = new TokenClient(disco.TokenEndpoint, "ro.client", "secret");
var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync("alice", "password", "api1");

if (tokenResponse.IsError)
{
    Console.WriteLine(tokenResponse.Error);
    return;
}

Console.WriteLine(tokenResponse.Json);
Console.WriteLine("\n\n");

But this is giving me following error.但这给了我以下错误。

error CS1729: 'TokenClient' does not contain a constructor that takes 3 arguments错误 CS1729:“TokenClient”不包含采用 3 个参数的构造函数

From the docs, it looks like that page is only applicable to Core 1.0.从文档来看,该页面似乎仅适用于 Core 1.0。 When I change the documentation to 3.1.0, I get当我将文档更改为 3.1.0 时,我得到

Sorry This pages does not exist yet抱歉 此页面尚不存在

Does this mean that ResourceOwnerPassword flow is not supported for the .NET Core 3.1?这是否意味着 .NET Core 3.1 不支持ResourceOwnerPassword流?

Ctrl + clicking on the method takes to to its signature, where you can find out the specific parameters that the method expects. Ctrl + 单击该方法会转到其签名,您可以在其中找到该方法所需的特定参数。

Browsing the repo, I've found this snippet on using the password credentials token request:浏览 repo,我发现了这个关于使用密码凭证令牌请求的片段:

var response = await _client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
    ClientId = "client",
    UserName = "user",
    Password = "password",
    Scope = "scope",
    Resource = { "resource1", "resource2" }
});

another overload:另一个重载:

var response = await tokenClient.RequestPasswordTokenAsync(userName: "user", password: "password", scope: "scope");

Or see the actual method definition or another helper .或者查看实际的方法定义或其他帮助程序

A useful tip: popular packages usually have a lot of tests .一个有用的提示:流行的包通常有很多测试 You can check them out to learn how to use the library.您可以查看它们以了解如何使用该库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM