Identity Server 4向已生成的令牌添加声明

时间:2018-12-09 00:49:51

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

我正在使用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;
}

如何向令牌添加声明?

1 个答案:

答案 0 :(得分:2)

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的源代码以了解内部调用是如何完成的。

相关问题