swagger-api / swagger-api/swagger-ui

window.opener is null in oauth2-redirect.html

Open
#8,030 5 comments 3 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

I have read all previously closed issues relating to this subject, but most answers are not very detailed.

I am using @nestjs/swagger for my swagger-ui.

Here is what my setup looks like

// I had to turn of CSP briefly, as the scripts on oauth2-redirect.html were not allowed to execute for some reason
  app.use(
    helmet({
      contentSecurityPolicy: false,
    }),
  );

  const config = new DocumentBuilder()
    .setTitle('ReNeuro API')
    .setVersion('1.0')
    .addOAuth2({
      type: 'oauth2',
      flows: {
        authorizationCode: {
          authorizationUrl: process.env.SWAGGER_AUTHORIZATION_URL,
          scopes: [],
        },
      },
    })
    .build();
  SwaggerModule.setup('docs', app, document, {
    swaggerOptions: {
      oauth: {
        clientId: process.env.SWAGGER_COGNITO_CLIENT_ID,
        clientSecret: process.env.SWAGGER_COGNITO_CLIENT_SECRET,
      },
    },
  });

When I click "Authorize"

I can login via my provider (cognito), and it successfully puts the code into the URL, but my oauth2-redirect.html page throws the following error:

Uncaught TypeError: Cannot read properties of null (reading 'swaggerUIRedirectOauth2')
    at run (oauth2-redirect.html)

I have tested on Firefox and Chrome, same issue.

Any help with this would be really appreciated

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 with oauth2-redirect.html and reproduce the Authorize flow in Chrome or Firefox using the configuration shown. Inspect the run path around the window.opener access and verify that the returned code is handled without the null-reference error; the issue is resolved when the redirect completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
authentication, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.