swagger-api / swagger-api/swagger-ui

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

Open
#10,438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

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 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the request/response lifecycle used by the Try it out interface and the existing Authorize modal logic. Add the proposed configuration behavior so a 401 response opens the modal, and verify that normal requests and authorization flows remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.