Skip to content

Commit 81ea2fd

Browse files
committed
Extend remote token lifetime
1 parent 75e7268 commit 81ea2fd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

netlify/functions/notify-comp-token.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const headers = {
1010
const base64Url = (value) => Buffer.from(value).toString('base64url');
1111
const REMOTE_SCOPE = 'notifycomp.remote';
1212
const PUSH_SCOPE = 'assignment_notifications';
13+
const REMOTE_TOKEN_TTL_SECONDS = 12 * 60 * 60;
14+
const PUSH_TOKEN_TTL_SECONDS = 10 * 60;
1315

1416
const signJwt = (claims, secret) => {
1517
const encodedHeader = base64Url(JSON.stringify({ alg: 'HS256', typ: 'JWT' }));
@@ -89,6 +91,8 @@ exports.handler = async (event) => {
8991
}
9092

9193
const tokenScope = scope === REMOTE_SCOPE ? REMOTE_SCOPE : PUSH_SCOPE;
94+
const tokenTtlSeconds =
95+
tokenScope === REMOTE_SCOPE ? REMOTE_TOKEN_TTL_SECONDS : PUSH_TOKEN_TTL_SECONDS;
9296
if (tokenScope === REMOTE_SCOPE && !competitionId) {
9397
return {
9498
statusCode: 400,
@@ -102,7 +106,7 @@ exports.handler = async (event) => {
102106
{
103107
aud: process.env.COMPETITION_GROUPS_JWT_AUDIENCE || 'notifycomp',
104108
competitionIds: tokenScope === REMOTE_SCOPE ? [competitionId] : undefined,
105-
exp: now + 10 * 60,
109+
exp: now + tokenTtlSeconds,
106110
iat: now,
107111
iss: process.env.COMPETITION_GROUPS_JWT_ISSUER || 'competitiongroups.com',
108112
name: me.name,

0 commit comments

Comments
 (0)