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

fix: update protection to accept array with multiples options #1565

Merged
merged 9 commits into from
Apr 6, 2021
2 changes: 1 addition & 1 deletion src/server/lib/oauth/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function getOAuth2AccessToken (code, provider, codeVerifier) {
headers.Authorization = `Bearer ${code}`
}

if (provider.protection === 'pkce') {
if ([provider.protection].flat().includes('pkce')) {
params.code_verifier = codeVerifier
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/lib/oauth/pkce-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const PKCE_MAX_AGE = 60 * 15 // 15 minutes in seconds
export async function handleCallback (req, res) {
const { cookies, provider, baseUrl, basePath } = req.options
try {
if (provider.protection !== 'pkce') { // Provider does not support PKCE, nothing to do.
if (![provider.protection].flat().includes('pkce')) { // Provider does not support PKCE, nothing to do.
return
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export async function handleCallback (req, res) {
export async function handleSignin (req, res) {
const { cookies, provider, baseUrl, basePath } = req.options
try {
if (provider.protection !== 'pkce') { // Provider does not support PKCE, nothing to do.
if (![provider.protection].flat().includes('pkce')) { // Provider does not support PKCE, nothing to do.
return
}
// Started login flow, add generated pkce to req.options and (encrypted) code_verifier to a cookie
Expand Down
4 changes: 2 additions & 2 deletions src/server/lib/oauth/state-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { OAuthCallbackError } from '../../../lib/errors'
export async function handleCallback (req, res) {
const { csrfToken, provider, baseUrl, basePath } = req.options
try {
if (provider.protection !== 'state') { // Provider does not support state, nothing to do.
if (![provider.protection].flat().includes('state')) { // Provider does not support state, nothing to do.
return
}

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

Expand Down
2 changes: 1 addition & 1 deletion www/docs/configuration/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ You can look at the existing built-in providers for inspiration.
| profile | An callback returning an object with the user's info | `object` | No |
| idToken | Set to `true` for services that use ID Tokens (e.g. OpenID) | `boolean` | No |
| headers | Any headers that should be sent to the OAuth provider | `object` | No |
| protection | Additional security for OAuth login flows (defaults to `state`) | `pkce`, `state`, `none` | No |
| protection | Additional security for OAuth login flows (defaults to `state`) |`[pkce]`,`[state]`,`[pkce,state]`| No |
| state | Same as `protection: "state"`. Being deprecated, use protection. | `boolean` | No |

## Sign in with Email
Expand Down