swagger-api / swagger-api/swagger-ui

Override the request for OAuth token or authorized() selector

Open
#5,733 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

  • OS - RHEL 7

  • Browser - Chrome

  • Version - 78.0.3904.108

  • Method of installation - npm

  • Swagger UI version - 3.24.2

  • Swagger 2.0, OpenAPI 3.0

  • Using petstore.json
    SwaggerUI({ spec: swagger, plugins: { statePlugins: { auth: { wrapActions: { // Override authorizing OAuth client credentials flow authorizeApplication: (oriAction, system) => swaggerProps => { ... fetchOauthTokenPending(); authenticationServices .fetchOAuthClientCredentialsToken(...) .then((response, error) => { fetchOauthTokenSuccess(response.data); const auth = { appName: swaggerProps.appName, name: swaggerProps.name, schema: swagger, scopes: scopes, clientId: clientId, clientSecret: clientSecret }; const token = response.data.access_token; return system.authActions.authorizeOauth2({auth: auth, token: token}); }) .catch(error => { fetchOauthTokenError(error); }); }, }, wrapSelectors: { authorized: (oriSelector, system) => (state, ...args) => { return system.authSelectors.getOAuthToken(); } }, selectors: { getOAuthToken: () => { const {oauthToken} = this.props; return !!oauthToken; } } } } } }); })

As we need to proxy the request for the OAuth token we need to override authorizeApplication action and in it we request the token. When we receive successfully the access token from the request we try to send it to authorizeOauth2 action as it is done in the original authorizeApplication action but without success. The token is not accepted.

The other thing I try is to override the authorized selector as I saw that it is being used in order to lock the Authorize button. It should be locked when we have the token in our state and because of that I put this logic in custom selector called getOAuthToken. But when I do this I receive this error:

image

Could you please help me and suggest what to do in order to authorize the application via proxy and not directly from the Swagger UI.
Or how to override this selector based on my logic?
Also debugging tips would be very welcomed.

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 Swagger UI's auth plugin implementation for the authorizeApplication action and authorized selector, using the provided petstore.json configuration to reproduce the behavior. Determine how proxied OAuth token authorization and selector overrides are expected to work; done means the application authorizes through the proxy without the token being rejected or the selector causing an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
authentication, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.