Skip to content

Commit 6420ddc

Browse files
authored
feat(oauth2-set-state): Allow set state in case it exists on oauth2 provider [#253]
2 parents 8e6cd92 + bda974e commit 6420ddc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/schemes/oauth2.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ auth: {
1818
token_type: 'Bearer',
1919
redirect_uri: undefined,
2020
client_id: 'SET_ME',
21-
token_key: 'access_token'
21+
token_key: 'access_token',
22+
state: 'UNIQUE_AND_NON_GUESSABLE'
2223
}
2324
}
2425
}
@@ -64,6 +65,11 @@ By default is set to `token_key: 'access_token'`. If you need to use the IdToken
6465

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

68+
### `state`
69+
70+
By default is set to random generated string.
71+
The primary reason for using the state parameter is to mitigate CSRF attacks. ([read more](https://auth0.com/docs/protocols/oauth2/oauth-state))
72+
6773
## Usage
6874

6975
```js

lib/schemes/oauth2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ export default class Oauth2Scheme {
7070
client_id: this.options.client_id,
7171
redirect_uri: this._redirectURI,
7272
scope: this._scope,
73-
state: randomString()
74-
}
73+
// Note: The primary reason for using the state parameter is to mitigate CSRF attacks.
74+
// @see: https://auth0.com/docs/protocols/oauth2/oauth-state
75+
state: this.options.state || randomString(),
76+
};
7577

7678
if (this.options.audience) {
7779
opts.audience = this.options.audience

0 commit comments

Comments
 (0)