Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with oAuth on Swagger-ui 3.0.3 #3260

Closed
northk opened this issue Jun 19, 2017 · 8 comments
Closed

Problem with oAuth on Swagger-ui 3.0.3 #3260

northk opened this issue Jun 19, 2017 · 8 comments

Comments

@northk
Copy link

northk commented Jun 19, 2017

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”
                });
@webron
Copy link
Contributor

webron commented Jun 19, 2017

There have been many updates to the OAuth2 support in the various releases. Please try the latest version first and report back.

@northk
Copy link
Author

northk commented Jun 19, 2017

Hello webron,
I downloaded the latest version (dated June 17th). When I run it using the following initOAuth() configuration, I get a 400 Bad Request with message {"message": "apikey missing"}.

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

I then tried the following initOAuth() config and this didn't work either:

swagger_ui_114.initOAuth(
                {
                    "apikey": "my_api_key_value_here"
                });

I also tried it without quotes around the key:

swagger_ui_114.initOAuth(
                {
                    apikey: "my_api_key_value_here"
                });

But none of these works.
Clicking the Authorize button and entering the same apikey value manually still works. When I do that, the resulting generated Curl call has a query parameter like the following. This query parameter is missing in the generated Curl call resulting from the initOAuth() calls which do not work:
?apikey=my_api_key_value_here

Please advise.
Thanks.

@webron
Copy link
Contributor

webron commented Jun 19, 2017

@bodnia can you take a look at this one?

@bodnia
Copy link
Contributor

bodnia commented 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.

@northk
Copy link
Author

northk commented Jun 20, 2017

Could using additionalQueryStringParams : {apikey: "my_api_key_value_here"} work as below? Or is that also not implemented yet?

swagger_ui_114.initOAuth(
  {
    additionalQueryStringParams : {apikey: "my_api_key_value_here"}
  });

Thanks

@bodnia
Copy link
Contributor

bodnia commented Jun 20, 2017

@northk it is implemented, but these params are added to authorization urls when making authorization calls in popup

@northk
Copy link
Author

northk commented 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.

@shockey
Copy link
Contributor

shockey commented Jul 3, 2017

Closing this support ticket due to inactivity.

The feature discussed here is, by my estimation, covered in this feature ticket: #2915

Feel free to comment or request a reopen if there are any lingering concerns.

@shockey shockey closed this as completed Jul 3, 2017
@lock lock bot locked and limited conversation to collaborators Jul 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants