Facebook
From Unreliable Meerkat, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 127
  1.   // configure strongly typed settings objects
  2.             var appSettingsSection = Configuration.GetSection("AppSettings");
  3.             services.Configure<AppSettings>(appSettingsSection);
  4.  
  5.             // configure jwt authentication
  6.             var appSettings = appSettingsSection.Get<AppSettings>();
  7.             var key = Encoding.ASCII.GetBytes(appSettings.Secret);
  8.             services.AddAuthentication(x =>
  9.             {
  10.                 x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
  11.                 x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
  12.             })
  13.             .AddJwtBearer(x =>
  14.             {
  15.                 x.RequireHttpsMetadata = false;
  16.                 x.SaveToken = true;
  17.                 x.TokenValidationParameters = new TokenValidationParameters
  18.                 {
  19.                     ValidateIssuerSigningKey = true,
  20.                     IssuerSigningKey = new SymmetricSecurityKey(key),
  21.                     ValidateIssuer = false,
  22.                     ValidateAudience = false
  23.                 };
  24.             });
  25.  
  26.             // configure DI for application services
  27.             services.AddScoped<IUserService, UserService>();
  28.