Problem with oAuth on Swagger-ui 3.0.3
See original GitHub issueGreetings 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:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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:
Thanks for your consideration.
@northk
initOAuthadds only configs for oauth2, you can also read about this hereInterface for authorising with js code instead of manually in popup is not released yet, but this is going to be soon.