Example #1
0
 public JWTFactory(IOptions <JWTIssuerOptions> jwtOptions, IOptions <AuthSettings> authSettings, ILogger logger)
 {
     if (_jwtTokenHandler == null)
     {
         _jwtTokenHandler = new JwtSecurityTokenHandler();
     }
     _jwtOptions   = jwtOptions.Value;
     _authSettings = authSettings.Value;
     _logger       = logger;
     ThrowIfInvalidOptions(_jwtOptions);
 }
Example #2
0
        private static void ThrowIfInvalidOptions(JWTIssuerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.ValidFor <= TimeSpan.Zero)
            {
                throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(JWTIssuerOptions.ValidFor));
            }

            if (options.SigningCredentials == null)
            {
                throw new ArgumentNullException(nameof(JWTIssuerOptions.SigningCredentials));
            }

            if (options.JtiGenerator == null)
            {
                throw new ArgumentNullException(nameof(JWTIssuerOptions.JtiGenerator));
            }
        }