/// <summary> /// Initializes a new <see cref="JwtSecurityTokenService"/> with the specified options /// </summary> public JwtSecurityTokenService(JwtSecurityTokenServiceOptions options) { var myOptions = options ?? new JwtSecurityTokenServiceOptions(); _diagnosticService = myOptions.DiagnosticService ?? DiagnosticService.DefaultInstance; _signingKey = myOptions.SigningKey; _fallbackSigningKey = myOptions.FallbackSigningKey; _defaultTtl = myOptions.DefaultTTL <= TimeSpan.Zero ? TimeSpan.FromDays(3) : myOptions.DefaultTTL; }
/// <inheritdoc /> public Task <ISecurityTokenService> CreateSecurityTokenService(SecurityTokensElement configuration) { var signingKey = (HexEncodedSecurityKey)configuration.GetString("signingKey"); var fallbackSigningKey = (HexEncodedSecurityKey)configuration.GetString("fallbackSigningKey"); var defaultTtl = configuration.GetTimeSpan("defaultTtl").GetValueOrDefault(); var options = new JwtSecurityTokenServiceOptions { SigningKey = signingKey, FallbackSigningKey = fallbackSigningKey, DefaultTTL = defaultTtl }; var securityTokenService = new JwtSecurityTokenService(options); return(Task.FromResult <ISecurityTokenService>(securityTokenService)); }
/// <inheritdoc /> public Task <ISecurityTokenService> CreateSecurityTokenService(IConfiguration configuration) { var signingKey = (HexEncodedSecurityKey)configuration?["signingKey"]; var fallbackSigningKey = (HexEncodedSecurityKey)configuration?["fallbackSigningKey"]; var options = new JwtSecurityTokenServiceOptions { SigningKey = signingKey, FallbackSigningKey = fallbackSigningKey }; var defaultTtl = configuration?.GetValue <TimeSpan>("defaultTtl"); if (defaultTtl > TimeSpan.Zero) { options.DefaultTTL = defaultTtl.Value; } var securityTokenService = new JwtSecurityTokenService(options); return(Task.FromResult <ISecurityTokenService>(securityTokenService)); }