Skip to content

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

Open
@dmytro-arkhypenko

Description

@dmytro-arkhypenko

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.

Activity

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[/+] on May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @dmytro-arkhypenko

      Issue actions

        Show Swagger UI logon window when API requests came back as 401 · Issue #10438 · swagger-api/swagger-ui