From 4ae351b06f15a7c4902fc07dbd93ab5022f89dc9 Mon Sep 17 00:00:00 2001 From: Govindarajan Nagarajan Date: Tue, 4 Aug 2020 18:48:38 +0200 Subject: [PATCH] Refactor: Make properties of `OAuthState` non-optional --- plugins/auth-backend/src/lib/OAuthProvider.ts | 10 +++++----- plugins/auth-backend/src/providers/types.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/auth-backend/src/lib/OAuthProvider.ts b/plugins/auth-backend/src/lib/OAuthProvider.ts index 6faaa9f733..8d8743d24b 100644 --- a/plugins/auth-backend/src/lib/OAuthProvider.ts +++ b/plugins/auth-backend/src/lib/OAuthProvider.ts @@ -46,13 +46,13 @@ const readState = (stateString: string): OAuthState => { new URLSearchParams(decodeURIComponent(stateString)), ); return { - nonce: state.nonce ?? undefined, - env: state.env ?? undefined, + nonce: state.nonce ?? '', + env: state.env ?? '', }; } catch (e) { return { - nonce: undefined, - env: undefined, + nonce: '', + env: '', }; } }; @@ -85,7 +85,7 @@ export const verifyNonce = (req: express.Request, providerId: string) => { if (!cookieNonce) { throw new Error('Auth response is missing cookie nonce'); } - if (!stateNonce) { + if (stateNonce.length === 0) { throw new Error('Auth response is missing state nonce'); } if (cookieNonce !== stateNonce) { diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index afb136fd0f..74ed75d57a 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -345,6 +345,6 @@ export type SAMLEnvironmentProviderConfig = { export type OAuthState = { /* A type for the serialized value in the `state` parameter of the OAuth authorization flow */ - nonce?: string; - env?: string; + nonce: string; + env: string; };