Skip to content

Commit b7826dd

Browse files
author
Vladimir Tkac
committed
Apply PR code suggestions
1 parent 721bc32 commit b7826dd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ fastify.register(oauthPlugin, {
9595
})
9696
```
9797

98+
Additionally, you can customize the names of the cookies by setting the `redirectStateCookieName` and `verifierCookieName` options.
99+
The default values for these cookies are `oauth2-code-verifier` for `verifierCookieName` and `oauth2-redirect-state` for `redirectStateCookieName`.
100+
101+
```js
102+
fastify.register(oauthPlugin, {
103+
...,
104+
redirectStateCookieName: 'custom-redirect-state',
105+
verifierCookieName: 'custom-code-verifier'
106+
})
107+
```
108+
98109
### Preset configurations
99110

100111
You can choose some default setup to assign to `auth` option.

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function defaultCheckStateFunction (request, callback) {
2828
const state = request.query.state
2929
const stateCookie =
3030
request.cookies[
31-
this.redirectStateCookieName || DEFAULT_REDIRECT_STATE_COOKIE_NAME
31+
this.redirectStateCookieName
3232
]
3333
if (stateCookie && state === stateCookie) {
3434
callback()
@@ -135,7 +135,9 @@ function fastifyOauth2 (fastify, options, next) {
135135
scope,
136136
generateStateFunction = defaultGenerateStateFunction,
137137
checkStateFunction = defaultCheckStateFunction.bind({
138-
redirectStateCookieName: configured.redirectStateCookieName
138+
redirectStateCookieName:
139+
configured.redirectStateCookieName ||
140+
DEFAULT_REDIRECT_STATE_COOKIE_NAME
139141
}),
140142
startRedirectPath,
141143
tags = [],

0 commit comments

Comments
 (0)