I'm using IdentityServerTools to Generate a token:
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;
}
How can I add a claim to the token?
an easier version of that for creating tokens for server-to-server communication (eg when you have to call an IdentityServer protected API from your code)
If you want more granular control over the token generated, use one of the overloads of IssueJwtAsync
:
Task<string> IssueJwtAsync(int lifetime, IEnumerable<Claim> claims)
// or
Task<string> IssueJwtAsync(int lifetime, string issuer, IEnumerable<Claim> claims)
You may want to check the source code for IssueClientJwtAsync
to see how the internal call is done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.