Trying to use bearer token based authentification in simple .Net Core Web API project. Here is my Startup.cs
app.UseMvc();
//---
const string secret
In ASP.NET Core, the order of the middleware matters: they are executed in the same order as they are registered. Here, app.UseMvc()
is called before the JWT bearer middleware, so this can't work.
Put app.UseMvc()
at the end of your pipeline and it should work:
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
TokenValidationParameters = tokenValidationParameters,
AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme,
});
app.UseMvc();