swagger icon indicating copy to clipboard operation
swagger copied to clipboard

SwaggerCustomOptions.swaggerOptions.oauth -> SwaggerCustomOptions.swaggerOptions.initOAuth

Open ac-tiffi opened this issue 3 years ago • 1 comments

Did you read the migration guide?

  • [X] I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Potential Commit/PR that introduced the regression

maybe #1886 not sure though

Versions

5.2.1 -> 6.1.0

Describe the regression

After the upgrade my authentication did not work anymore. After some investigation I got it working again by using
initOAuth instead of oauth:

SwaggerModule.setup('api', app, document, {
      customJs: `data:text/javascript;base64,${SWAGGER_UI_CORS_WORKAROUND}`,
      swaggerOptions: {
        persistAuthorization: true,
        initOAuth: {
          usePkceWithAuthorizationCodeGrant: true,
        },
      },
    });

It took me some time to find this. Is that anywhere documented? I couldn't find the change. Maybe it should be documented here: https://docs.nestjs.com/migration-guide

Also it would be helpfull if there were typescript types documenting this.

Minimum reproduction code

setup swagger with the oauth / initOAuth option

SwaggerModule.setup('api', app, document, {
      customJs: `data:text/javascript;base64,${SWAGGER_UI_CORS_WORKAROUND}`,
      swaggerOptions: {
        persistAuthorization: true,
        initOAuth: {
          usePkceWithAuthorizationCodeGrant: true,
        },
      },
    });

Expected behavior

Either document that somewhere or provide backwards compatibility.

Other

No response

ac-tiffi avatar Aug 31 '22 12:08 ac-tiffi

I spent some time trying to get it to work myself. I got it to work by moving initOAuth outside of swaggerOptions, like so:

const customOptions: SwaggerCustomOptions = {
  customSiteTitle: 'ProjectName API - Swagger',
  swaggerOptions: {
    clientId: swaggerClientId,
    oauth2RedirectUrl: `http://localhost:3000${apiBasePath}/docs/oauth2-redirect.html`,
    swaggerOptions: {
      persistAuthorization: false,
      docExpansion: 'list',
      deepLinking: true,
      oauth2RedirectUrl: `http://localhost:3000${apiBasePath}/docs/oauth2-redirect.html`,
    },
    initOAuth: {
      clientId: swaggerClientId,
      scopes: [scope],
      appName: 'appNamefillinnhere',
      usePkceWithAuthorizationCodeGrant: true,
    },
  },
};

Definitely think it would be good to both add this to the migration guide, as well as going into a bit more detail in the docs for this library as well.

gabrielhandeland avatar Sep 21 '22 10:09 gabrielhandeland

cc @flamewow 🤔

kamilmysliwiec avatar Oct 24 '22 07:10 kamilmysliwiec

Thanks for catching the issue, guys. I've came up with the fix PR: https://github.com/nestjs/swagger/pull/2138

flamewow avatar Oct 25 '22 12:10 flamewow

Let's track this here https://github.com/nestjs/swagger/pull/2138

kamilmysliwiec avatar Oct 26 '22 06:10 kamilmysliwiec