Skip to content

Instantly share code, notes, and snippets.

@jakkaj
Created August 3, 2016 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakkaj/46ba343f3232289e754cc081ad57dd9e to your computer and use it in GitHub Desktop.
Save jakkaj/46ba343f3232289e754cc081ad57dd9e to your computer and use it in GitHub Desktop.
JWT Validation using ASP.NET Core build in stuff
//From <https://stormpath.com/blog/token-authentication-asp-net-core>
var tokenValidationParameters = new TokenValidationParameters
{
// The signing key must match!
ValidateIssuerSigningKey = true,
IssuerSigningKey = signingKey,
// Validate the JWT Issuer (iss) claim
ValidateIssuer = true,
ValidIssuer = "ExampleIssuer",
// Validate the JWT Audience (aud) claim
ValidateAudience = true,
ValidAudience = "ExampleAudience",
// 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