Skip to content

Instantly share code, notes, and snippets.

@ugurcemozturk
Last active April 7, 2019 12:23
Show Gist options
  • Save ugurcemozturk/c92995de82c534c6a3207c4e13663b3d to your computer and use it in GitHub Desktop.
Save ugurcemozturk/c92995de82c534c6a3207c4e13663b3d to your computer and use it in GitHub Desktop.
namespace dotnetJWT.Configuration
{
public static class JwtConfiguration
{
public static void ConfigureJwt(IServiceCollection services)
{
services.AddAuthentication(configureOptions =>
{
configureOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
configureOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
jwtOptions.RequireHttpsMetadata = true;
jwtOptions.SaveToken = false;
jwtOptions.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new JsonWebKey("JWK_PUBLIC"),
ValidateIssuer = true,
ValidIssuer = "issuer",
ValidateAudience = true,
ValidAudience = "clientOrigin",
ValidateLifetime = true,
ValidateTokenReplay = true,
ClockSkew = TimeSpan.FromMinutes(1)
};
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment