Hi,
I am using asp.net core 2.2 and i am trying to implement multi authentication(bearer, basic) for my API. Here is my startup
services.AddOptions(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])) }; }); services.Configure<Jwt>(Configuration.GetSection("Jwt")); services.AddAuthentication("BasicAuthentication") .AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
The class basic BasicAuthenticationHandler has the logic to parse the authorization hearder nd validate with my backend .
i followed the below link to implement
https://forums.asp.net/t/2158279.aspx?Basic+Authentication+Bearer+Jwt+Authentication
configure method in startup:
app.UseAuthentication(); app.UseMvc();
Controller level specification:
[Authorize(AuthenticationSchemes = "BasicAuthentication")] [Route("api/[controller]")] [ApiController] public class UserController: ControllerBase { }after adding all the logic, tried to test with post man, i am getting 401 unauthorized. my break point doesnpt even comes to AuthenticateHandler
Error from post man :
This error occurs when the WWW-Authenticate header sent to the Web server is not supported by the server configuration. Check the authentication method for the resource, and verify which authentication method the client used. The error occurs when the authentication methods are different. To determine which type of authentication the client is using, check the authentication settings for the client.<p><a href="https://go.microsoft.com/fwlink/?LinkID=62293&IIS70Error=401,2,0x80070005,17134">View more information »</a></p><p>Microsoft Knowledge Base Articles:</p>
not sure where am doing mistake. is there any working sample that implements bearer and basic on same project? Please share me the source code for reference.