Created
December 9, 2016 17:32
-
-
Save samueleresca/66256d739cb20c0a848f8c43240f12b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Startup | |
{ | |
public SymmetricSecurityKey signingKey; | |
private void ConfigureAuth(IApplicationBuilder app) | |
{ | |
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("TokenAuthentication:SecretKey").Value)); | |
var tokenValidationParameters = new TokenValidationParameters | |
{ | |
// The signing key must match! | |
ValidateIssuerSigningKey = true, | |
IssuerSigningKey = signingKey, | |
// Validate the JWT Issuer (iss) claim | |
ValidateIssuer = true, | |
ValidIssuer = Configuration.GetSection("TokenAuthentication:Issuer").Value, | |
// Validate the JWT Audience (aud) claim | |
ValidateAudience = true, | |
ValidAudience = Configuration.GetSection("TokenAuthentication:Audience").Value, | |
// Validate the token expiry | |
ValidateLifetime = true, | |
// If you want to allow a certain amount of clock drift, set that here: | |
ClockSkew = TimeSpan.Zero | |
}; | |
app.UseJwtBearerAuthentication(new JwtBearerOptions | |
{ | |
AutomaticAuthenticate = true, | |
AutomaticChallenge = true, | |
TokenValidationParameters = tokenValidationParameters | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment