2

如本文所述,我在 Asp.Net Web Api 项目中实现了授权服务器。

现在我需要使用来自 .Net c# 客户端的服务。在 IdentityModel文档中,我可以看到以下示例:

var client = new TokenClient(
    "https://server/token",
    "client_id",
    "secret");

var response = await client.RequestClientCredentialsAsync("scope");
var token = response.AccessToken;

问题:

  1. 拥有客户端 ID 和客户端密码的目的是什么?
  2. 如何使用用户凭据对用户进行身份验证?
  3. 如何在客户端访问用户声明?
  4. 它是什么Scope以及它的用途是什么?
4

1 回答 1

0

using IdentityModel.Client;代币可以通过以下方式消费。

 var client = new TokenClient(authenticationUrl);
 client.Timeout = TimeSpan.FromSeconds(60);
 var tokenResponse = await client.RequestResourceOwnerPasswordAsync(userName, password);
 var handler = new JwtSecurityTokenHandler();
 var token = handler.ReadJwtToken(tokenResponse.AccessToken);

token本身包含声明属性。

于 2017-05-31T12:54:17.860 回答