public static IServiceCollection AddAuth(this IServiceCollection services,
                                                 AuthenticationSettings settings)
        {
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer   = true,
                    ValidIssuer      = settings.Url,
                    ValidateAudience = true,
                    ValidAudience    = settings.Url,
                    ValidateLifetime = true,
                    IssuerSigningKey =
                        new SymmetricSecurityKey(Encoding.ASCII.GetBytes(settings.SecretJwtKey)),
                };
            });

            return(services
                   .AddTransient <IUserContextService, UserContextService>());
        }
Exemple #2
0
 public AuthModuleBuilder(IServiceCollection services, AuthenticationSettings settings)
     : base(services)
 {
     _settings = settings;
 }