swagger-api / swagger-api/swagger-ui

Topbar - add support for per-API auth settings

Open
#8,634 1 comment 1 reaction 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

Desired capability

When the Swagger UI configuration includes a urls property the top bar is enabled, so the user can switch between APIs. This has proven quite convenient, but the topbar apparently strips away any auth configuration you might have applied.

I would like to be able to include initial auth settings in the list of APIs:

{
    name: 'API Name',
    url: 'https:// ...',
    auth: {
        usePkceWithAuthorizationCodeGrant: true,
        clientId: 'string',
        scopes: 'string string',
        // ... other initial auth settings
    }
},

...and have those (re)applied when the API selection changes.

Explanation

Certain auth settings can only be set in the UI. The usePkceWithAuthorizationCodeGrant flag is a good example. Okta requires the use of PKCE when using Authorization Code flow. This means the topbar plugin is incompatible with Okta + auth code flow.

I'm not experienced enough with React/Redux to follow all of the code, but it looks like this occurs in src/plugins/topbar/topbar.jsx:

  flushAuthData() {
    const { persistAuthorization } = this.props.getConfigs()
    if (persistAuthorization)
    {
      return
    }
    this.props.authActions.restoreAuthorization({
      authorized: {}
    })
  }

  loadSpec = (url) => {
    this.flushAuthData()
    this.props.specActions.updateUrl(url)
    this.props.specActions.download(url)
  }

Workaround

If the settings can't be included in the API list, then I can wire up my own selection box instead of using the plugin. But I would need to know what methods to call on the instance to reset everything properly. Is it sufficient to just call SwaggerUIBundle and initOAuth methods again? (If someone clears this up I'll be happy to submit a PR for the docs on this.)

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 in src/plugins/topbar/topbar.jsx, reading loadSpec and flushAuthData alongside the auth and spec actions they call. Trace how entries in the urls list are selected and how authorization is restored; the work is done when an API entry's initial auth settings are reapplied after selection changes without breaking the existing persistence behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react, redux
Domain
authentication, 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.