Skip to content

Commit

Permalink
Allow bearer auth in header using sessionToken (#6276)
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamsi authored Aug 9, 2021
1 parent 8a640ec commit 3a7a06b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/four-turkeys-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/keystone': minor
'@keystone-next/api-tests-legacy': minor
---

Added option for `Bearer` token auth when using session.
9 changes: 5 additions & 4 deletions packages/keystone/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ export function statelessSessions<T>({
}
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 }) {
Expand Down
3 changes: 1 addition & 2 deletions tests/api-tests/auth-header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 3a7a06b

Please sign in to comment.