Ejemplo n.º 1
0
        private static IServiceCollection AddAuthenticationService(
            this IServiceCollection services,
            JwtConfiguration jwtConfiguration)
        {
            var secretBytes = Encoding.UTF8.GetBytes(jwtConfiguration.Secret);

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey = new SymmetricSecurityKey(secretBytes),
                    ValidateIssuer   = false,
                    ValidateAudience = false,
                    ValidIssuer      = jwtConfiguration.ValidIssuer,
                    ValidAudience    = jwtConfiguration.ValidAudience
                };
            });

            return(services);
        }
Ejemplo n.º 2
0
        public JwtEncryptor(
            JwtConfiguration configuration,
            IClaimsIdentityConverter claimsProvider)
        {
            _configuration           = configuration;
            _claimsIdentityConverter = claimsProvider;

            _secretCached = Encoding.UTF8.GetBytes(configuration.Secret);
        }
Ejemplo n.º 3
0
 private static IServiceCollection AddJwtConfiguration(
     this IServiceCollection services,
     JwtConfiguration instance)
 {
     return(services.AddSingleton(typeof(JwtConfiguration), instance));
 }