【问题标题】:Identity Server 4 Add a claim to a generated tokenIdentity Server 4 向生成的令牌添加声明
【发布时间】:2018-12-09 10:17:48
【问题描述】:

我正在使用 IdentityServerTools 生成令牌:

private async Task<string> CreatePaymentsTokenAsync()
{
    var tokenLifeTime = 3600;
    var scopes = new[] { CoinbaseAuthConsts.PaymentScope };
    // Use in-built Identity Server tools to issue JWT
    var token = await _identityServerTools.IssueClientJwtAsync(
            CoinbaseAuthConsts.AuthorityClientId, 
            tokenLifeTime, scopes, new[] { "AstootApi" });
    return token;
}

如何向令牌添加声明?

【问题讨论】:

    标签: c# authentication asp.net-core identityserver4


    【解决方案1】:

    IssueClientJwtAsync is

    为服务器到服务器通信创建令牌的更简单版本(例如,当您必须从代码中调用受 IdentityServer 保护的 API 时)

    如果您想对生成的令牌进行更精细的控制,请使用IssueJwtAsync 的重载之一:

    Task<string> IssueJwtAsync(int lifetime, IEnumerable<Claim> claims)
    // or
    Task<string> IssueJwtAsync(int lifetime, string issuer, IEnumerable<Claim> claims)
    

    您可能需要查看IssueClientJwtAsync 的源代码以了解内部调用是如何完成的。

    【讨论】:

      猜你喜欢
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 2020-08-06
      • 2017-06-29
      相关资源
      最近更新 更多