Skip to content

OAuth2 flow not completing #1384

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

Closed
lucian303 opened this issue Jun 19, 2015 · 4 comments
Closed

OAuth2 flow not completing #1384

lucian303 opened this issue Jun 19, 2015 · 4 comments
Milestone

Comments

@lucian303
Copy link
Contributor

I have the following config:

securityDefinitions:
  oauth2:
    type: oauth2
    flow: accessCode
    description: OAuth2 Security
    tokenUrl: "https://myserver.com/token"
    authorizationUrl: "https://myserver.com/authorize"
    scopes:
      read: Read data.

The URLs are valid. When I click the On/Off switch, I get asked for the scope. I pick the only scope we have and click 'Authorize.' I get redirected to my oAuth login where I log in with valid credentials. I get redirected back to o2c.html with the proper oAuth code. That code calls window.opener.processOAuthCode(qp); then closes the window. Swagger UI then calls the /token endpoint but doesn't provide the client secret. This is where the flow fails.

Which I suppose is to be expected because this block in index.html makes no sense:

            initOAuth({
              clientId: "swagger",
              realm: "your-realms",
              appName: "your-app-name"
            });

The clientId is correct and it's set up correctly to redirect back to o2c.html. I have no idea what realm and appName are supposed to be or how they'd relate to oAuth in this case. I also tried using the implicit oAuth flow but had no luck with that as I don't think our server supports it.

So my questions:

  1. Can I authenticate with oAuth2 and if so what needs to be done to make the flow finish properly?
  2. Even when manually adding the appropriate Authorization header in the JS using swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer some_hash_here", "header")); the API fails to make the call with this header. It's displayed in the curl call which works perfectly using curl so it's not an issue with the API itself but swagger. This is my fallback position for allowing testing of the oAuth2 API if Added regex to replace / with _ in resource name #1 above doesn't work, assuming that swagger-ui can be made to actually send the headers properly.
@webron
Copy link
Contributor

webron commented Jun 21, 2015

Which version of the UI do you use?

@lucian303
Copy link
Contributor Author

I'm on 2.1.1 (master). As a further update to this, I dug in and found out that this was failing during the /token endpoint request because it was not sending in the expected client_secret parameter to the endpoint. When I add that manually in, it works fine. As far as I know the /token endpoint requires both the client and secret. Am I wrong?

If it helps, my swagger installation is at: https://omtdev.unifiedcompliance.com:8500

@ankon
Copy link
Contributor

ankon commented Jun 25, 2015

This looks much related to #1324 - adding the client secret does fix the issue (PR upcoming if no one beats me to it :) )

@lucian303
Copy link
Contributor Author

@ankon Yes, it is the same issue / fix.

fehguy added a commit that referenced this issue Jul 23, 2015
Add support for oauth client secret when calling the token URL. Fixes #1384. Fixes #1324.
@fehguy fehguy closed this as completed in 1fd15c6 Jul 23, 2015
@webron webron added this to the v2.1.1 milestone Jul 31, 2015
vincent-zurczak pushed a commit to roboconf/swagger-ui that referenced this issue Aug 19, 2016
Add support for oauth client secret when calling the token URL. Fixes swagger-api#1384. Fixes swagger-api#1324.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants