Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Created April 29, 2018 08:47
Show Gist options
  • Select an option

  • Save wellingtonjhn/5ab4cbcf6bb6025020fdd8e4ca6cb628 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/5ab4cbcf6bb6025020fdd8e4ca6cb628 to your computer and use it in GitHub Desktop.
AddJwtAuthorization Method
private static void AddJwtAuthorization(IServiceCollection services)
{
var jwtSettings = services.BuildServiceProvider().GetRequiredService<JwtSettings>();
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(jwtBearerOptions =>
{
jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateActor = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = jwtSettings.Issuer,
ValidAudience = jwtSettings.Audience,
IssuerSigningKey = jwtSettings.SigningCredentials.Key
};
});
services.AddAuthorization();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment