Created
November 4, 2017 13:21
-
-
Save StephanyBatista/63f89a316dfa66e5a1750a47d3b3fd66 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 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