Trying to use bearer token based authentification in simple .Net Core Web API project. Here is my Startup.cs
app.UseMvc();
//---
const string secret
For .NET Core 3.0 you would need:
In ConfigureServices(IServiceCollection services)
:
services.AddAuthentication()
.AddJwtBearer(options =>
{
options.Authority = issuer;
options.Audience = audience;
options.TokenValidationParameters = tokenValidationParameters;
});
In Configure(IApplicationBuilder app, IWebHostEnvironment env)
:
// Add it after app.UseRouting() and before app.UseEndpoints()!
// Order of middlewares is important!
app.UseAuthentication();
app.UseAuthorization();
PS: To omit authentication scheme indication in [Authorize]
attribute you could set the default authentication scheme in ConfigureServices(IServiceCollection services)
in AuthenticationOptions
options:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
});