question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access swagger-ui after setup to initialize oauth2

See original GitHub issue

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

It is not possible to initialize ouath2 parameters.

Looking at the doc https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/

ui.initOAuth({
    clientId: "your-client-id",
    clientSecret: "your-client-secret-if-required",
    realm: "your-realms",
    appName: "your-app-name",
    scopeSeparator: " ",
    scopes: "openid profile",
    additionalQueryStringParams: {test: "hello"},
    usePkceWithAuthorizationCodeGrant: true
  })

Describe the solution you’d like

Either SwaggerModule.setup() should return an instantiated swagger-ui or we should add configuration option that could trigger the setup of ui.initOauth().

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Cannot pre configure oauth2 configuration such as clientId.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
julianklumperscommented, Mar 31, 2022

You can achieve this with swaggerOptions

SwaggerModule.setup('api', app, document, {
  customSiteTitle: 'Your API',
  swaggerOptions: {
    oauth: {
      clientId: "your-client-id",
      clientSecret: "your-client-secret-if-required",
      realm: "your-realms",
      appName: "your-app-name",
      scopeSeparator: " ",
      scopes: ["openid", "profile"],
      additionalQueryStringParams: {test: "hello"},
      usePkceWithAuthorizationCodeGrant: true
    },
    persistAuthorization: true,
  },
});
0reactions
dan-cookecommented, Oct 11, 2022

Does anybody else find swagger to be just incredibly messy and have a terrible DX.

I almost always advocate for GraphQL purely because of how annoying Swagger is to configure.

Prime example…

Why is there a function initOauth()

But for some reason, you don’t pass theredirectUrl in this part… instead you configure it in the parent swagger options config? as oauth2RedirectUrl

Like come on.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger UI OAuth 2.0 configuration
You can configure OAuth 2.0 authorization by calling the initOAuth method. ... Method can be called in any place after calling constructor SwaggerUIBundle ......
Read more >
How to do OAuth2 Authorization in ASP.NET Core for ...
NET Core for Swagger UI using Swashbuckle ... To enable OAuth2 authentication, first we need to write the following code.
Read more >
How to configure oAuth2 with password flow with Swagger ui ...
The best way so far to work with oAuth2 Authorisation is by using Swagger Editor, I have installed Swagger Editor quickly in Docker...
Read more >
ASP.NET Core Swagger UI Authorization using IdentityServer4
To configure the Swagger UI as a client application in your IdentityServer implementation, you'll need to add a client entry within ...
Read more >
Keycloak Integration – OAuth2 and OpenID with Swagger UI
As we can see, both the service provider and the service consumer need to contact the Keycloak server. First, we'll need to install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found