/// <summary> /// Creates a serialized and protected security token. /// </summary> /// <param name="token">The token.</param> /// <returns> /// A security token in serialized form /// </returns> /// <exception cref="System.InvalidOperationException">Invalid token type.</exception> public virtual async Task <string> CreateSecurityTokenAsync(Token token) { string tokenResult; if (token.Type == OidcConstants.TokenTypes.AccessToken) { if (token.AccessTokenType == AccessTokenType.Jwt) { _logger.LogTrace("Creating JWT access token"); tokenResult = await _creationService.CreateTokenAsync(token); } else { _logger.LogTrace("Creating reference access token"); var handle = CryptoRandom.CreateUniqueId(); await _grants.StoreReferenceTokenAsync(handle, token); tokenResult = handle; } } else if (token.Type == OidcConstants.TokenTypes.IdentityToken) { _logger.LogTrace("Creating JWT identity token"); tokenResult = await _creationService.CreateTokenAsync(token); } else { throw new InvalidOperationException("Invalid token type."); } await _events.RaiseTokenIssuedEventAsync(token, tokenResult); return(tokenResult); }