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

Allow set state in case it exists on oauth2 provider #253

Merged
merged 3 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion docs/schemes/oauth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ auth: {
token_type: 'Bearer',
redirect_uri: undefined,
client_id: 'SET_ME',
token_key: 'access_token'
token_key: 'access_token',
state: 'UNIQUE_AND_NON_GUESSABLE'
Copy link
Member

Choose a reason for hiding this comment

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

This should be random per login not documented here

Copy link
Member

Choose a reason for hiding this comment

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

My bad
You're right, state must keep random and internal.
We could persist our custom values with auth storage in order to recover them on OAuth2 callback

}
}
}
Expand Down Expand Up @@ -64,6 +65,11 @@ By default is set to `token_key: 'access_token'`. If you need to use the IdToken

By default is set to `refresh_token_key: 'refresh_token'`. It automatically store the refresh_token, if it exists.

### `state`

By default is set to random generated string.
The primary reason for using the state parameter is to mitigate CSRF attacks. ([read more](https://auth0.com/docs/protocols/oauth2/oauth-state))

## Usage

```js
Expand Down
6 changes: 4 additions & 2 deletions lib/schemes/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ export default class Oauth2Scheme {
client_id: this.options.client_id,
redirect_uri: this._redirectURI,
scope: this._scope,
state: randomString()
}
// Note: The primary reason for using the state parameter is to mitigate CSRF attacks.
// @see: https://auth0.com/docs/protocols/oauth2/oauth-state
state: this.options.state || randomString(),
};

if (this.options.audience) {
opts.audience = this.options.audience
Expand Down