Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bearer auth in header using sessionToken #6276

Merged
merged 4 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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