swagger-api / swagger-api/swagger-ui

After authenticating with OIDC the Authentication header has value "Bearer undefined"

Open
#9,392 1 comment 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: [e.g. Ubuntu]
  • Browser: [e.g. chrome,]
  • Version: [e.g. 5.0.0-5.10.0]
  • Method of installation: [e.g. dist ]
  • Swagger-UI version: [e.g. 5.10.0]
  • Swagger/OpenAPI version: [e.g. OpenAPI 3.1]
Content & configuration
{
    "openapi": "3.1.0",
    "info": {
        "title": "",
        "summary": "",
        "version": ""
    },
    "components": {
        "securitySchemes": {
            "OpenId": {
                "type": "openIdConnect",
                "openIdConnectUrl": "openid configuration discovery endpoint"
            }
        }
    },
    "security": [
        {
            "OpenId": [
                "openid"
            ]
        }
    ]
}

The security scheme and global security definition is added manually to the openapi.json file prepared by Fastapi.

Swagger-UI configuration options:

    const ui = SwaggerUIBundle({
        url: '/openapi.json',
    "dom_id": "#swagger-ui",
"layout": "BaseLayout",
"deepLinking": true,
"showExtensions": true,
"showCommonExtensions": true,
oauth2RedirectUrl: window.location.origin + '/docs/oauth2-redirect',
    presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIBundle.SwaggerUIStandalonePreset
        ],
    })

The response from open id url/token looks as follows:

{
    "id_token": "correct token",
    "token_type": "Bearer",
    "not_before": 1700229612,
    "id_token_expires_in": 3600,
    "profile_info": "encoded profile info",
    "scope": "openid"
}

Sensitive information has been removed

Describe the bug you're encountering

When the openid flow is finished and the id_token is obtained from the openid domain/token the Authentication header sent to our API has value "Bearer undefined". To the best of my knowledge swagger ui should obtain the access token from oauth 2 using the id token.

To reproduce...

Create and configure an application using openid connect for use in your local environment. Manually add the security definitions as above to the openapi file and log in.

Expected behavior

Access token is obtained and sent to the Fastapi app.

Screenshots

ss1
ss2

Additional context or thoughts

The noticeable difference from our frontend that uses msal for auth is not obtaining the access token after having obtained the id_token. When the request is made the access token is undefined but the auth flow is finished and the user is marked as authenticated. Similar issues were reported in the past when users would expect the security definitions to be applied by default without a global security scheme but this is not the case here.

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 reproducing the OIDC flow with the provided OpenAPI configuration and SwaggerUIBundle options, then inspect the request generated after authentication. Trace how the response's id_token and token_type are mapped to the Authentication header; done means the API request sends a usable access token instead of "Bearer undefined".

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, javascript
Domain
api, 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.