Bearer token is not used by Swagger for endpoints with [authorize], but used for [AllowAnonymous]
Hey!
Yesterday while working on a project for university I encountered a strange bug, which can be seen in the screens below:
- When an endpoint is marked with the
[Authorize]
attribute, even if a Bearer Token is specified in Swagger, this Token will not be used in the execution of the request.
- If we use the [AllowAnonymous]
attribute instead of [Authorize]
, the Bearer Token will be sent in the request.
The described behaviour can be seen in the screenshots. Does anyone know what might be generating it? And how can I fix it?4 Replies
my Program.cs
endpoint in UserController.cs
Nevermind, I found the reason why it didn't work.
For some reason, adding
opts.OperationFilter<SecurityRequirementsOperationFilter>();
to the Swagger config disabled attaching bearer token to the request, when it had [Authorize]
attribute on itself.Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View