示例#1
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllers();
     services.AddSpaStaticFiles(config => config.RootPath = "client/build");
     InterfaceConfig.Configure(services, _configuration);
     JwtConfig.Configure(services, _configuration);
 }
示例#2
0
        private void ConfigureJwt(IServiceCollection services)
        {
            var issuer    = AppConfig.GetValue <string>("JWT:Issuer");
            var key       = AppConfig.GetValue <string>("JWT:Key");
            var jwtConfig = new JwtConfig(issuer, key);

            services.AddSingleton <JwtConfig>(jwtConfig);
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = true;
                options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
                {
                    ValidateIssuer = true,
                    ValidIssuer    = jwtConfig.Issuer,

                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = jwtConfig.GetSymmetricSecurityKey(),

                    ValidateLifetime = false,
                    ValidateAudience = false
                };
            });
            services.AddAuthorization();
        }