【问题标题】:Asp.Net Web Api 2 - How to consume JWT access token and user claims using Identity ModelAsp.Net Web Api 2 - 如何使用身份模型使用 JWT 访问令牌和用户声明
【发布时间】:2016-05-01 09:15:04
【问题描述】:

我已经在 Asp.Net Web Api 项目中实现了一个授权服务器,如 article 中所述。

现在我需要使用来自 .Net c# 客户端的服务。在 IdentityModel documentation 我可以看到下面的例子:

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是什么,有什么用?

【问题讨论】:

    标签: asp.net asp.net-web-api2 asp.net-identity claims thinktecture-ident-model


    【解决方案1】:

    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 本身包含声明属性。

    【讨论】:

      猜你喜欢
      • 2016-04-30
      • 2017-10-29
      • 2016-01-02
      • 2019-06-22
      • 2021-09-17
      • 2021-09-30
      • 2017-10-05
      • 2017-06-24
      • 2015-01-27
      相关资源
      最近更新 更多