diff --git a/.changeset/four-turkeys-hide.md b/.changeset/four-turkeys-hide.md new file mode 100644 index 00000000000..5dab9b7e327 --- /dev/null +++ b/.changeset/four-turkeys-hide.md @@ -0,0 +1,6 @@ +--- +'@keystone-next/keystone': minor +'@keystone-next/api-tests-legacy': minor +--- + +Added option for `Bearer` token auth when using session. diff --git a/packages/keystone/src/session/index.ts b/packages/keystone/src/session/index.ts index 3f16ecd60f2..9843ebe8c9b 100644 --- a/packages/keystone/src/session/index.ts +++ b/packages/keystone/src/session/index.ts @@ -87,11 +87,12 @@ export function statelessSessions({ } return { async get({ req }) { - if (!req.headers.cookie) return; - let cookies = cookie.parse(req.headers.cookie); - if (!cookies[TOKEN_NAME]) return; + const cookies = cookie.parse(req.headers.cookie || ''); + const bearer = req.headers.authorization?.replace('Bearer ', ''); + const token = bearer || cookies[TOKEN_NAME]; + if (!token) return; try { - return await Iron.unseal(cookies[TOKEN_NAME], secret, ironOptions); + return await Iron.unseal(token, secret, ironOptions); } catch (err) {} }, async end({ res }) { diff --git a/tests/api-tests/auth-header.test.ts b/tests/api-tests/auth-header.test.ts index c64eeda9a61..13c4e9f1a6c 100644 --- a/tests/api-tests/auth-header.test.ts +++ b/tests/api-tests/auth-header.test.ts @@ -118,8 +118,7 @@ describe('Auth testing', () => { }); describe('logged in', () => { - // eslint-disable-next-line jest/no-disabled-tests - test.skip( + test( 'Allows access with bearer token', runner(async ({ context, graphQLRequest }) => { for (const [listKey, data] of Object.entries(initialData)) {