You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Minimal APIs with Asp.Versioning.Mvc 8.1.0.
I have Authentication and Authorization enabled with default JWT-Bearer Authentication scheme and default Authorization policy (the only requirement is DenyAnonymousAuthorizationRequirement).
As expected, with Authentication/Authorization disabled, I get a 400 Bad Request response when I provide an invalid API version in a client request (or omit the API version altogether).
However, if I enable Authentication/Authorization, and use .AllowAnonymous() to bypass the authorization requirement on an endpoint, I get a 401 Unauthorized response for the same requests.
Is this the expected behavior? Either way, is there a way to work around this so that we can return a 401 response?
Expected Behavior
When I use .AllowAnonymous() on an endpoint, I expect to receive a 401 Bad Request when a client request omits the API version or provides an invalid API version.
I might be missing something, but I don't see a mapping for 1.1. My best guess is that endpoint selection is being short-circuited and returning 401 before API versioning has a chance to return 400.
If you add support for 1.1, then I expect it to work the same way as 1.0, which seems to be correct:
What response should I get when I run curl http://localhost:5080/foo?
I would expect either 200 Ok, or 400 Bad Request because I'm missing the required, valid API version (1.0). But instead, I'm getting a 401 Unauthorized, which is simply incorrect.
If I remove ApiVersioning and run that command, I get a 200 Ok:
Perhaps something is being short-circuited but it would seem to be a bug because it's short-circuiting the .AllowAnonymous(). The documentation for AllowAnonymous says "This will bypass all authorization checks for the endpoint including the default authorization policy and fallback authorization policy".
I'm happy to work around it if you have any insights. Thanks!
Is there an existing issue for this?
Describe the bug
I am using Minimal APIs with Asp.Versioning.Mvc 8.1.0.
I have Authentication and Authorization enabled with default JWT-Bearer Authentication scheme and default Authorization policy (the only requirement is
DenyAnonymousAuthorizationRequirement
).As expected, with Authentication/Authorization disabled, I get a
400 Bad Request
response when I provide an invalid API version in a client request (or omit the API version altogether).However, if I enable Authentication/Authorization, and use
.AllowAnonymous()
to bypass the authorization requirement on an endpoint, I get a401 Unauthorized
response for the same requests.Is this the expected behavior? Either way, is there a way to work around this so that we can return a 401 response?
Expected Behavior
When I use
.AllowAnonymous()
on an endpoint, I expect to receive a401 Bad Request
when a client request omits the API version or provides an invalid API version.Steps To Reproduce
Minimal server to reproduce:
Demo:
Exceptions (if any)
No response
.NET Version
9.0.102
Anything else?
No response
The text was updated successfully, but these errors were encountered: