I'm developing a web api core 2.0 project.
I need support two authorization types: jwt and basic.
Inside my ConfigureServices method I've added this code:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer((options) =>
{
options.Authority = $"...";
options.Audience = "...";
});
services.AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
.AddBasicAuthentication(credentials =>
Task.FromResult(
credentials.username == "username"
&& credentials.password == "password"));
Inside my Configure method I've added this code:
app.UseAuthentication();
app.UseMvc();
And finally I've added AuthorizeAttribute on my controller:
[Authorize]
public class MioController : Controller
{ ... }
Actually work only the last authentication specified on ConfigureServices.
How can I support both authentication types? Thanks
Note: I'm using this NuGet package for basic authentication Bazinga.AspNetCore.Authentication.Basic.
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]