SwaggerCustomOptions.swaggerOptions.oauth -> SwaggerCustomOptions.swaggerOptions.initOAuth
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
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.
cc @flamewow 🤔
Thanks for catching the issue, guys. I've came up with the fix PR: https://github.com/nestjs/swagger/pull/2138
Let's track this here https://github.com/nestjs/swagger/pull/2138