From 9c058761331578b2e4b4da6f308a64319016999a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ov=C4=8Da=C4=8D=C3=ADk?= Date: Wed, 16 Oct 2024 11:02:48 +0200 Subject: [PATCH] Pass client secret to cookie adapter --- src/session-adapters/createCookieAdapter.ts | 4 +++- src/session/sessionStore.ts | 5 ++++- src/storyblok-auth-api/auth-handler.ts | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/session-adapters/createCookieAdapter.ts b/src/session-adapters/createCookieAdapter.ts index 98c7451..39dafc9 100644 --- a/src/session-adapters/createCookieAdapter.ts +++ b/src/session-adapters/createCookieAdapter.ts @@ -3,15 +3,17 @@ import jwt from 'jsonwebtoken' import { Adapter } from './publicAdapter' import { isAppSession } from '../session' -const clientSecret = process.env['CLIENT_SECRET'] || '' const defaultSessionKey = 'sb.auth' +const defaultClientSecret = process.env['CLIENT_SECRET'] || '' type CreateCookieAdapter = (params?: { sessionKey?: string | undefined + clientSecret?: string | undefined }) => Adapter export const createCookieAdapter: CreateCookieAdapter = (params) => { const key = params?.sessionKey ?? defaultSessionKey + const clientSecret = params?.clientSecret ?? defaultClientSecret const adapter: Adapter = { getSession: ({ req, spaceId, userId }) => { diff --git a/src/session/sessionStore.ts b/src/session/sessionStore.ts index 9d87704..5914c2b 100644 --- a/src/session/sessionStore.ts +++ b/src/session/sessionStore.ts @@ -16,7 +16,10 @@ export const getSessionStore: AppSessionCookieStoreFactory = params, req: requestParams.req, res: requestParams.res, - adapter: createCookieAdapter({ sessionKey: params.sessionKey }), + adapter: createCookieAdapter({ + sessionKey: params.sessionKey, + clientSecret: params.clientSecret, + }), }) return { diff --git a/src/storyblok-auth-api/auth-handler.ts b/src/storyblok-auth-api/auth-handler.ts index 06cda92..a5f8936 100644 --- a/src/storyblok-auth-api/auth-handler.ts +++ b/src/storyblok-auth-api/auth-handler.ts @@ -22,7 +22,10 @@ export const authHandler = ( params, req, res, - adapter: createCookieAdapter({ sessionKey: params.sessionKey }), + adapter: createCookieAdapter({ + sessionKey: params.sessionKey, + clientSecret: params.clientSecret, + }), }) const responseElement = await handleAnyRequest({