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

C# Identity Server 4向生成的令牌添加声明,c#,authentication,asp.net-core,identityserver4,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

我正在使用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;
}
private异步任务CreatePaymentsTokenAsync()
{
var-tokenlife=3600;
var scopes=new[]{CoinbaseAuthConsts.PaymentScope};
//使用内置的Identity Server工具发布JWT
var token=await_identityServerTools.IssueClientJwtAsync(
CoinbaseAuthConsts.AuthorityClientId,
令牌生命周期,作用域,新[]{“astotapi”});
返回令牌;
}
如何向令牌添加声明

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

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

Task<string> IssueJwtAsync(int lifetime, IEnumerable<Claim> claims)
// or
Task<string> IssueJwtAsync(int lifetime, string issuer, IEnumerable<Claim> claims)
Task IssueJwtAsync(int生存期,IEnumerable声明)
//或
任务IssueJwtAsync(int生存期、字符串颁发者、IEnumerable声明)
您可能需要检查源代码以了解内部调用是如何完成的