Use initOAuth & requestInterceptor for swagger configuration
Hi, I hope I didn't miss anything but it seems like foal/swagger does not support calling initOAuth from the ui options so that the use case described in the documentation of swagger here works: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/ (see Instance Methods)
The ultimate goal is to be able to set (1) the default clientId and (2) most importantly the audience via the additionalQueryStringParams (both described in the config documentation here: https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/.)
Without that unfortunately OAuth with Auht0 does not work as they require the audience to be set.
Here is my current code where i tried to get around (2) by intercepting the response and setting the audience manually but the console.log doesn't get triggered when i execute a request from the ui:
export class OpenApiController extends SwaggerController {
options = { controllerClass: ApiController };
uiOptions = {
persistAuthorization: true,
oauth2RedirectUrl: 'http://localhost:3002/oauth2-redirect.html',
// add audience to the request if we call the authorize endpoint
requestInterceptor: (request: SwaggerRequest) => {
console.log(request);
if (
request.url.endsWith('oauth/token')
) {
...
}
return request;
},
};
}
In addition it seems like the package is not generating the /oauth2-redirect.html as shown here https://github.com/swagger-api/swagger-ui/blob/master/dev-helpers/oauth2-redirect.html even though foal/swagger automatically generates the redirect uri http://localhost:3002/swagger/oauth2-redirect.html and passes it on to the OAuth auth request. I could get around this by manually placing the file in /public and defining the redirect url as shown above.
Just wanted to note this since it seems like a bug that it doesn't get generated.
Would appreciate any input on how to get around (1) and (2). Cheers!