Open ManoNero opened 6 days ago
Hi @ManoNero. To help us investigate this issue, could you please provide us a project that reproduces the problem?
Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.
Hi,
I'm using .NET 8.0 and encountering an issue with setting the default authentication scheme. Despite specifying
JwtBearerDefaults.AuthenticationScheme
as the default, it doesn't seem to be recognized in my controllers.Authentication Configuration:
Here's how I've set up authentication in my
Program.cs
:Controller Setup:
In my controller, I'm using the
[Authorize]
attribute without specifying any scheme:Issue:
With the above setup, authentication doesn't work as expected. The
[Authorize]
attribute does not utilize the default scheme specified (JwtBearerDefaults.AuthenticationScheme
). As a result, JWT authentication fails, and authorized endpoints are not accessible.Workaround:
To make it work, I have to explicitly specify the authentication scheme in the
[Authorize]
attribute:Expected Behavior:
By setting the default authentication scheme using
AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
, I expect the[Authorize]
attribute to automatically use this scheme without needing to specify it explicitly in every controller or action.Actual Behavior:
The default authentication scheme is ignored unless explicitly specified in the
[Authorize]
attribute.Questions:
Is this the expected behavior in .NET 8.0 when multiple authentication schemes are registered?
How can I configure the default authentication scheme to be used by
[Authorize]
without specifying it each time, while still supporting multiple schemes?Environment:
Any guidance on resolving this issue or clarification on whether this is intended behavior would be greatly appreciated.
Thank you!