Skip to content

Instantly share code, notes, and snippets.

@StephanyBatista
Created November 4, 2017 13:21
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 StephanyBatista/63f89a316dfa66e5a1750a47d3b3fd66 to your computer and use it in GitHub Desktop.
Save StephanyBatista/63f89a316dfa66e5a1750a47d3b3fd66 to your computer and use it in GitHub Desktop.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => {
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "stephanybatista.com",
ValidAudience = "stephanybatista.com",
IssuerSigningKey = JwtSecurityKey.Create("a-password-very-big-to-be-good")
};
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = context =>
{
Console.WriteLine("OnAuthenticationFailed: " + context.Exception.Message);
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
Console.WriteLine("OnTokenValidated: " + context.SecurityToken);
return Task.CompletedTask;
}
};
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseMvc();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment