C
C#6d ago
Salight

✅[Authorize] Doesn't Recognize Default Authentication Scheme?

In my API, when I use
[Authorize]
[Authorize]
, sending a request from Postman with a valid token returns a 404 error. However, when I explicitly set
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
, authentication works fine. Why isn't
JwtBearerDefaults.AuthenticationScheme
JwtBearerDefaults.AuthenticationScheme
recognized as the default? Additional Info: I am using
AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
in my configuration. The token is valid, and my MVC client authenticates successfully. In Postman, I send the Authorization header as
Bearer {token}
Bearer {token}
. How can I fix this?
2 Replies
OlujA
OlujA6d ago
can you add this?

services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})

services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
Salight
SalightOP6d ago
Okay i solved i just changed the configuration alignment and it solved

Did you find this page helpful?