/// <summary> /// Creates an access token. /// </summary> /// <param name="request">The token creation request.</param> /// <returns> /// An access token /// </returns> public virtual async Task <Token> CreateAccessTokenAsync(TokenCreationRequest request) { _logger.LogVerbose("Creating access token"); request.Validate(); var claims = new List <Claim>(); claims.AddRange(await _claimsProvider.GetAccessTokenClaimsAsync( request.Subject, request.Client, request.Scopes, request.ValidatedRequest)); if (request.Client.IncludeJwtId) { claims.Add(new Claim(Constants.ClaimTypes.JwtId, CryptoRandom.CreateUniqueId())); } var issuer = _context.GetIssuerUri(); var token = new Token(Constants.TokenTypes.AccessToken) { Audience = string.Format(Constants.AccessTokenAudience, issuer.EnsureTrailingSlash()), Issuer = issuer, Lifetime = request.Client.AccessTokenLifetime, Claims = claims.Distinct(new ClaimComparer()).ToList(), Client = request.Client }; return(token); }
/// <summary> /// Creates an access token. /// </summary> /// <param name="request">The token creation request.</param> /// <returns> /// An access token /// </returns> public virtual async Task <Token> CreateAccessTokenAsync(TokenCreationRequest request) { Logger.Debug("Creating access token"); request.Validate(); var claims = new List <Claim>(); claims.AddRange(await _claimsProvider.GetAccessTokenClaimsAsync( request.Subject, request.Client, request.Scopes, request.ValidatedRequest)); if (request.Client.IncludeJwtId) { claims.Add(new Claim(Constants.ClaimTypes.JwtId, CryptoRandom.CreateUniqueId())); } if (request.ProofKey.IsPresent()) { claims.Add(new Claim(Constants.ClaimTypes.Confirmation, request.ProofKey, Constants.ClaimValueTypes.Json)); } return(CreateAccessToken(request.Client, claims)); }
public virtual async Task <Token> CreateAccessTokenAsync(ClaimsPrincipal subject, Client client, IEnumerable <Scope> scopes, NameValueCollection request) { var claims = await _claimsProvider.GetAccessTokenClaimsAsync( subject, client, scopes, _settings, _users, request); var token = new Token(Constants.TokenTypes.AccessToken) { Audience = string.Format(Constants.AccessTokenAudience, _settings.IssuerUri), Issuer = _settings.IssuerUri, Lifetime = client.AccessTokenLifetime, Claims = claims.ToList(), Client = client }; return(token); }
/// <summary> /// Creates an access token. /// </summary> /// <param name="request">The token creation request.</param> /// <returns> /// An access token /// </returns> public virtual async Task <Token> CreateAccessTokenAsync(TokenCreationRequest request) { Logger.Debug("Creating access token"); request.Validate(); var claims = await _claimsProvider.GetAccessTokenClaimsAsync( request.Subject, request.Client, request.Scopes, request.ValidatedRequest); var token = new Token(Constants.TokenTypes.AccessToken) { Audience = string.Format(Constants.AccessTokenAudience, _options.IssuerUri.EnsureTrailingSlash()), Issuer = _options.IssuerUri, Lifetime = request.Client.AccessTokenLifetime, Claims = claims.Distinct(new ClaimComparer()).ToList(), Client = request.Client }; return(token); }