Description
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
andXMLHttpRequest
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.
Activity
[-]Show Swagger UI logon window is API requests came back as 401[/-][+]Show Swagger UI logon window when API requests came back as 401[/+]