From c9bab6d5963c2a7857d88f2d343b372cd75866fb Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 9 Aug 2021 16:55:32 +0200 Subject: [PATCH] auth-backend: read and encode the entire state object in encodeState and readState Signed-off-by: Patrik Oldsberg --- plugins/auth-backend/src/lib/oauth/helpers.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/auth-backend/src/lib/oauth/helpers.ts b/plugins/auth-backend/src/lib/oauth/helpers.ts index df84d421bd..ead9acae27 100644 --- a/plugins/auth-backend/src/lib/oauth/helpers.ts +++ b/plugins/auth-backend/src/lib/oauth/helpers.ts @@ -29,18 +29,14 @@ export const readState = (stateString: string): OAuthState => { ) { throw Error(`Invalid state passed via request`); } - return { - nonce: state.nonce, - env: state.env, - }; + + return state as OAuthState; }; export const encodeState = (state: OAuthState): string => { - const searchParams = new URLSearchParams(); - searchParams.append('nonce', state.nonce); - searchParams.append('env', state.env); + const stateString = new URLSearchParams(state).toString(); - return Buffer.from(searchParams.toString(), 'utf-8').toString('hex'); + return Buffer.from(stateString, 'utf-8').toString('hex'); }; export const verifyNonce = (req: express.Request, providerId: string) => {