public static IServiceCollection UseAuthentication(this IServiceCollection services, AuthOptions tokenOptions)
        {
            var jwtTokenValidator = new JwtSecurityTokenHandler();
            var validator         = new TokenValidator(jwtTokenValidator);

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = TokenGenerator.CreateTokenValidationParameters(tokenOptions.SecretKey, tokenOptions.EncryptionKey);
                options.RequireHttpsMetadata      = false;
                //todo refactor to default to true for prod and false for dev
            });
            return(services);
        }
Esempio n. 2
0
 public JwtDataFormat(TokenValidator tokenValidator, string secretKey, string encryptionKey)
 {
     _tokenValidator = tokenValidator;
     _encryptionKey  = encryptionKey;
     _secretKey      = secretKey;
 }