Example #1
0
        public static void UseAuthenticationSettings(this IApplicationBuilder app,
                                                     ICorsConfiguration corsConfiguration,
                                                     IJWTConfiguration jwtConfiguration)
        {
            if (!corsConfiguration.IsEnabled() || !jwtConfiguration.IsEnabled())
            {
                return;
            }

            app.UseCors(builder => builder
                        .WithOrigins(corsConfiguration.Origins)
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        //.AllowCredentials()
                        );

            app.UseAuthentication();
            app.UseAuthorization();
        }
Example #2
0
        public static void AddAuthenticationSettings(this IServiceCollection services, IJWTConfiguration jwtConfiguration, IJWTManager jwtManager)
        {
            if (!jwtConfiguration.IsEnabled())
            {
                return;
            }

            services.AddAuthentication(opt =>
            {
                opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                opt.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                opt.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(opt =>
            {
                //opt.RequireHttpsMetadata = false;
                //opt.Authority = "http://localhost:5000";
                opt.SaveToken = true;
                opt.TokenValidationParameters = jwtManager.GetTokenValidationParameters();
            });
            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(POLICY_NAME, GenerateAuthorizationPolicy());
            });
        }