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.

Problem with oAuth on Swagger-ui 3.0.3

See original GitHub issue

Greetings Swagger UI team,

I’m attempting to use oAuth to make calls after constructing an instance of SwaggerUIBundle, as below. I’m using Swagger UI 3.0.3. I can authorize and make calls without issue using the Authorize button manually and entering in the same key and value manually. But, when I attempt to authorize API calls using initOAuth() using the same key and value as I entered manually, I get a Not Authorized error. The Swagger UI instance is rendering normally. There are no Javascript console errors. Can someone please help? Thanks.

const swagger_ui_114 = SwaggerUIBundle({
                    url: ‘my_swagger_file_here.json',
                    dom_id: '#swagger-ui-container-114',
                    validatorUrl: null,     
                    docExpansion: 'none',
                    supportedSubmitMethods: '["get", "post", "put", "delete"]',
                    presets: [
                      SwaggerUIBundle.presets.apis,
                      SwaggerUIStandalonePreset
                    ],
                    plugins: [
                      SwaggerUIBundle.plugins.DownloadUrl
                    ],
                    layout: 'StandaloneLayout',    });

                swagger_ui_114.initOAuth({
                    clientId: "apikey",
                    clientSecret: “my_api_key_value_here”
                });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
northkcommented, Jun 20, 2017

OK thanks. It would be a very useful feature to support the apikey and value being specified in the initOAuth() call or otherwise connected with the SwaggerUIBundle object in some way. In swagger 2.x we could programmatically pass the apikey and value into the SwaggerUi object, and it worked well as below. Unfortunately at the moment this leaves us in a situation where previous functionality that worked on our site, no longer works:

Swagger 2.x approach:

authorizations: {
      "api_key" : new SwaggerClient.ApiKeyAuthorization("'.$key.'", "'.$value.'", "query")
    }';

Thanks for your consideration.

1reaction
bodniacommented, Jun 20, 2017

@northk initOAuth adds only configs for oauth2, you can also read about this here

Interface for authorising with js code instead of manually in popup is not released yet, but this is going to be soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication
description: Something is wrong. Scopes. OAuth 2 and OpenID Connect use scopes to control permissions to various user resources. For example, the scopes...
Read more >
springdoc / Swagger UI not passing OAuth2 token to API
I have confirmed via JS debugger that the Swagger UI received and stored a valid authentication token.
Read more >
OpenAPI 3 Library for spring-boot
OpenAPI 3 Library for spring boot projects. Is based on swagger-ui, to display the OpenAPI description.Generates automatically the OpenAPI ...
Read more >
Set JWT with Spring Boot and Swagger UI
In this short tutorial, we're going to see how to configure Swagger UI to include a JSON Web Token (JWT) when it calls...
Read more >
Swagger UI tutorial | Documenting APIs
i am also having this problem. I tried pasting the existing code example with the API key but it no longer works. OAuth...
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