-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing or bad formatted authorization header when adding basic auth to protect access to swagger doc #742
Comments
This is how basic authentication works. The browser try send a request to your server and the server ask back the authentication credentials. |
But it works, why does it throw the error and works as if nothing happened? There must be something I can do... |
Because you receive an error response (401) - https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication |
Look, I don't wanna be rude or anything, but what you've said is obvious, I already know that. I wanna know what can I do to fix this? Because, as I've mentioned, this doesn't happen when I'm running the environment localy... |
In case anyone finds themselves here with the same issue, it can be mitigated disabling swagger UI's online validator, as mentioned in this Stack Overflow post. fastify.register(fastifySwaggerUi, {
routePrefix: "/docs",
uiConfig: {
docExpansion: "none",
deepLinking: true,
validatorUrl: null, /* <-- add this line */
},
...
}); It must be something related to cors, but as I have little experience with it, I can't pinpoint the issue. |
This should be solved via fastify/fastify-swagger-ui#105 Closing ;). |
Prerequisites
Issue
After adding basic auth to protect access to our swagger docs, every time I open the URL, after typing the user/password and being granted access, the server throws this error. The weird thing is that this only happens when the code is executed in the production server, when I test localy, this issue doesn't happen. I'm pretty sure this has something to do with cors but I have no idea how to fix it. Specially since my cors config is as open as possible at the moment.
This is the error that is thrown, it doesnt affect the usability of the page. I tested all my routes using the token added through the Authorize button and it works just fine, it's just that it throws this error and the page also loads an invalid badge at the bottom.
This is the code for the basic authentication:
This is my fastify-swagger config:
This is my fastify-swagger-ui config:
This is my fastify-cors config:
It only happens ONCE, when the page is loaded and then it doesn't happen again until I reload the page.
Any ideia why this is happening?
The text was updated successfully, but these errors were encountered: