Skip to content

Show Swagger UI logon window when API requests came back as 401 #10438

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

Open
dmytro-arkhypenko opened this issue May 2, 2025 · 0 comments · May be fixed by #10441
Open

Show Swagger UI logon window when API requests came back as 401 #10438

dmytro-arkhypenko opened this issue May 2, 2025 · 0 comments · May be fixed by #10441

Comments

@dmytro-arkhypenko
Copy link

Is your feature request related to a problem?

Yes. Swagger UI does not currently offer a way to automatically trigger the login/authorize modal when a 401 Unauthorized response is returned by an API request. This causes confusion for users who may not realize that they are unauthenticated or need to re-authenticate.


Describe the solution you'd like

A built-in option to automatically open the Authorize modal when a 401 response is detected from a request made via the "Try it out" interface. This could be exposed as a new configuration option, e.g.:

SwaggerUI({
  autoPromptAuthOn401: true
})

Internally, Swagger UI would hook into the request/response lifecycle, and when it detects a 401, it would programmatically trigger the same logic used when the user clicks the "Authorize" button.


Describe alternatives you've considered

  • Writing a Tampermonkey userscript to monkey-patch fetch and XMLHttpRequest in the browser to detect 401s and click the authorize button. While this works, it's fragile, not portable, and requires advanced end-user customization.
  • Modifying the source code locally and maintaining a fork — not sustainable for long-term use or upgrades.

Additional context

This feature would improve the UX for secure APIs where sessions expire or where authorization is required for most endpoints. The approach has already been proven effective via userscripts and would be even better if natively supported.

@dmytro-arkhypenko dmytro-arkhypenko changed the title Show Swagger UI logon window is API requests came back as 401 Show Swagger UI logon window when API requests came back as 401 May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant