Skip to content

Commit 5a3ee47

Browse files
feat(provider): accept array for protection to support multiple mechanisms (#1565)
* fix: add protection both option * feat: update docs with new protection value * fix: lint files * refactor: change protection from string to array * chore: reverting unespected change * chore: lint files Co-authored-by: Balázs Orbán <[email protected]>
1 parent 8dd8f7c commit 5a3ee47

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/server/lib/oauth/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function getOAuth2AccessToken (code, provider, codeVerifier) {
136136
headers.Authorization = `Bearer ${code}`
137137
}
138138

139-
if (provider.protection === 'pkce') {
139+
if ([provider.protection].flat().includes('pkce')) {
140140
params.code_verifier = codeVerifier
141141
}
142142

src/server/lib/oauth/pkce-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const PKCE_MAX_AGE = 60 * 15 // 15 minutes in seconds
1616
export async function handleCallback (req, res) {
1717
const { cookies, provider, baseUrl, basePath } = req.options
1818
try {
19-
if (provider.protection !== 'pkce') { // Provider does not support PKCE, nothing to do.
19+
if (![provider.protection].flat().includes('pkce')) { // Provider does not support PKCE, nothing to do.
2020
return
2121
}
2222

@@ -50,7 +50,7 @@ export async function handleCallback (req, res) {
5050
export async function handleSignin (req, res) {
5151
const { cookies, provider, baseUrl, basePath } = req.options
5252
try {
53-
if (provider.protection !== 'pkce') { // Provider does not support PKCE, nothing to do.
53+
if (![provider.protection].flat().includes('pkce')) { // Provider does not support PKCE, nothing to do.
5454
return
5555
}
5656
// Started login flow, add generated pkce to req.options and (encrypted) code_verifier to a cookie

src/server/lib/oauth/state-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { OAuthCallbackError } from '../../../lib/errors'
1212
export async function handleCallback (req, res) {
1313
const { csrfToken, provider, baseUrl, basePath } = req.options
1414
try {
15-
if (provider.protection !== 'state') { // Provider does not support state, nothing to do.
15+
if (![provider.protection].flat().includes('state')) { // Provider does not support state, nothing to do.
1616
return
1717
}
1818

@@ -41,7 +41,7 @@ export async function handleCallback (req, res) {
4141
export async function handleSignin (req, res) {
4242
const { provider, baseUrl, basePath, csrfToken } = req.options
4343
try {
44-
if (provider.protection !== 'state') { // Provider does not support state, nothing to do.
44+
if (![provider.protection].flat().includes('state')) { // Provider does not support state, nothing to do.
4545
return
4646
}
4747

www/docs/configuration/providers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ You can look at the existing built-in providers for inspiration.
141141
| profile | An callback returning an object with the user's info | `object` | No |
142142
| idToken | Set to `true` for services that use ID Tokens (e.g. OpenID) | `boolean` | No |
143143
| headers | Any headers that should be sent to the OAuth provider | `object` | No |
144-
| protection | Additional security for OAuth login flows (defaults to `state`) | `pkce`, `state`, `none` | No |
144+
| protection | Additional security for OAuth login flows (defaults to `state`) |`[pkce]`,`[state]`,`[pkce,state]`| No |
145145
| state | Same as `protection: "state"`. Being deprecated, use protection. | `boolean` | No |
146146

147147
## Sign in with Email

0 commit comments

Comments
 (0)