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

WIP: Add Oauth2 Password flow #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

guillemcanal
Copy link

This feature add support for the Oauth2 password flow when described like so in a Swagger 2.0 file:

securityDefinitions:
  auth:
    type: oauth2
    flow: password
    tokenUrl: http://domain.tld/oauth/token

This is pretty much a work in progress because it don't include unit/functional tests and it contains some unrelated work here and there, but I think it's worth a look ;)

@darosh
Copy link
Owner

darosh commented Nov 16, 2016

@guillemcanal Thanks for your PR. I appreciate it, but the "work in progress" and "unrelated work" stuff makes it (hoping understandably) harder to analyze for me. :). Do you know about any live spec and instance we could use for simple test of the UI of this password flow? Like some specs in https://apis.guru/browse-apis/ ?
This repo seems to be popular (42 stars, yay!) so I will probably update it (beginning with dependencies update etc first) soon.

@guillemcanal
Copy link
Author

Yup sorry for the mess. I'll clean that up A.S.A.P.

Regarding the security scheme section, it is well documented on the official OpenAPI/Swagger2.0 specification

Basically, an oauth2 password is not that different, except that you don't need an authorizationUrl

We you have:

securityDefinitions:
  myAuth:
    type: oauth2
    flow: password
    tokenUrl: http://my.oauth-server.tld/token
    scopes:
      read: Read anything
      write: Write anything
      god: Activate god mode

...and the following on an operation:

/something:
  get:
    summary: Get something
    description: Blah Blah...
    responses:
      200:
        description: Yeah! Okay
    security:
      - myAuth: [read, write]

Then the oauth2 form should ask for a username and password. It will then issue a request to the endpoint described in securityDefinitions.myAuth.tokenUrl to obtain a token:

curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=password&client_id=swagger-ui&username=johndoe&password=p@$$w0rd' \
http://my.oauth-server.tld/token

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

Successfully merging this pull request may close these issues.

2 participants