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

Added information about auth code exchange to oauth2 docs #392

Merged
merged 3 commits into from
Mar 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions docs/oauth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,32 @@ the consent flow looks like this:
![Consent Flow](/images/consent.png)

1. A *client* application (app in browser in laptop) requests an access token from a resource owner:
`https://hydra.myapp.com/oauth2/auth?client_id=c3b49cf0-88e4-4faa-9489-28d5b8957858&response_type=code&scope=core+hydra&state=vboeidlizlxrywkwlsgeggff&nonce=tedgziijemvninkuotcuuiof`.
`GET https://hydra.myapp.com/oauth2/auth?client_id=c3b49cf0-88e4-4faa-9489-28d5b8957858&response_type=code&scope=core+hydra&state=vboeidlizlxrywkwlsgeggff&nonce=tedgziijemvninkuotcuuiof`.
2. Hydra generates a consent challenge and forwards the *user agent* (browser in laptop) to the *consent endpoint*:
`https://login.myapp.com/?challenge=eyJhbGciOiJSUzI1N...`.
`GET https://login.myapp.com/?challenge=eyJhbGciOiJSUzI1N...`.
3. The *consent endpoint* verifies the resource owner's identity (e.g. cookie, username/password login form, ...).
The consent challenge is then decoded and the information extracted. It is used to show the consent screen: `Do you want to grant _my cool app_ access to all your private data? [Yes] [No]`
4. When consent is given, the *consent endpoint* generates a consent response token and redirects the user
agent (browser in laptop) back to hydra:
`https://hydra.myapp.com/oauth2/auth?client_id=c3b49cf0-88e4-4faa-9489-28d5b8957858&response_type=code&scope=core+hydra&state=vboeidlizlxrywkwlsgeggff&nonce=tedgziijemvninkuotcuuiof&consent=eyJhbGciOiJSU...`.
5. Hydra validates the consent response token and issues the access token to the *user agent*.
`GET https://hydra.myapp.com/oauth2/auth?client_id=c3b49cf0-88e4-4faa-9489-28d5b8957858&response_type=code&scope=core+hydra&state=vboeidlizlxrywkwlsgeggff&nonce=tedgziijemvninkuotcuuiof&consent=eyJhbGciOiJSU...`.
5. Hydra validates the consent response token and issues the auth code to the *user agent*. The *user agent* is then redirected to the *client* application at the registered callback uri with the auth code as a parameter:
`GET https://example.com/callback?code=aaabbbcccddd`
6. The *client* application pairs this auth code with their client id and client secret, and requests an access token (and optionally the refresh token) from Hydra. This request must contain an Authorization header, which contains a Base64'd id/secret pairing (`client-id:client-secret`), sent as Basic authentication:

```
POST https://hydra.myapp.com/oauth2/token
Authorization: Basic BASE64_ID_SECRET_PAIR
Content-Type: application/x-www-form-urlencoded
code=aaabbbcccddd&redirect_uri=https://example.com/callback&grant_type=authorization_code
```
7. If your *client* application needs to exchange a refresh token for a new access token, this request looks similar to the auth code exchange, with the `grant_type` parameter altered, and the `code` parameter replaced with `refresh_token`:

```
POST https://hydra.myapp.com/oauth2/token
Authorization: Basic BASE64_ID_SECRET_PAIR
Content-Type: application/x-www-form-urlencoded
refresh_token=REFRESH_TOKEN&redirect_uri=https://example.com/callback&grant_type=refresh_token
```

### Consent App Flow Example

Expand Down Expand Up @@ -203,4 +220,4 @@ the authorization context of the token from the authorization server
to the protected resource.

The Token Introspection endpoint is documented in the
[API Docs](http://docs.hdyra.apiary.io/#reference/oauth2/oauth2-token-introspection).
[API Docs](http://docs.hdyra.apiary.io/#reference/oauth2/oauth2-token-introspection).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this line is listed as a change... I made this update in the Github UI if that helps at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe due to newline