swagger-api / swagger-api/swagger-ui

Swagger does not set Authorization Bearer header in safari when page is secured by Http Auth

Open
#6,954 2 comments 2 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

Q&A (please complete the following information)
  • OS: macOS
  • Browser: safari, but not chrome
  • Version: 14.0.3
  • Method of installation: dist assets
  • Swagger-UI version: 3.43.0
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
  1. I have installed Swagger UI Bundle under /explorer URL and secured it with HTTP Auth.
  2. API is secured with OAuth2 Authorization Code flow, but not HTTP Auth.

Example Swagger/OpenAPI definition:

openapi: 3.0.2
// ... 
components:
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: /auth/authorize
          tokenUrl: /auth/token
          refreshUrl: /auth/token
          scopes: { }    # No scopes in API for now
security:
  - oauth2: []

Swagger-UI configuration options:

    var swagger = SwaggerUIBundle({
        dom_id: '#swagger-root',
        url: '{{ apiDefinitionFilename }}',
        oauth2RedirectUrl: '{{ url('api_swagger_oauth2_redirect') }}',
        deepLinking: true,
        filter: true,
        displayRequestDuration: true,
        persistAuthorization: true,
        showMutatedRequest: true
    });
    swagger.initOAuth({
        clientId: '{{ client.key }}',
        clientSecret: '{{ client.secret }}',
        usePkceWithAuthorizationCodeGrant: true
    });
Describe the bug you're encountering

In Safari browser, Swagger UI Bundle does not send oauth token after valid authorization. Header Authorization is ovewritten by Authorization: Basic .... instead of Authorization: Bearer ...

Chome browser sends correct Authorization header at the same time.

To reproduce...

Steps to reproduce the behavior:

  1. Enter swagger UI URL secured by HTTP AUTH.
  2. Make an OAuth authorization in Swagger UI.
  3. Make an authorized request to API (secured by OAuth token).
  4. See inspector in web browser. The URL sent to server is different than generated curl request.
Expected behavior

Http Authorization header is not overriden by Authorization: Basic ... in case when Swagger is secured by HTTP AUTH.

Screenshots

swagger

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

Reproduce the report with Swagger UI 3.43.0 dist assets in Safari 14.0.3: secure the UI with HTTP Auth, authorize through the OpenAPI 3.0 OAuth2 authorization-code flow, and inspect the resulting API request. Compare Safari with Chrome and verify that the request sends the OAuth Bearer token rather than an HTTP Auth Basic header.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
authentication, frontend
Issue type
Bug
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.