From 914f86f1d7b6e4cce53c3a322f49c7481fa79805 Mon Sep 17 00:00:00 2001 From: Maxim Date: Tue, 26 Nov 2024 18:15:34 +0300 Subject: [PATCH] Extend token expiry time (#30) --- lib/units/auth/ldap.js | 3 ++- lib/units/auth/mock.js | 3 ++- lib/units/auth/oauth2/index.js | 3 ++- lib/units/auth/saml2.js | 3 ++- lib/util/jwtutil.js | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/units/auth/ldap.js b/lib/units/auth/ldap.js index ddc957ded..f98d38f7d 100644 --- a/lib/units/auth/ldap.js +++ b/lib/units/auth/ldap.js @@ -15,6 +15,7 @@ import * as pathutil from '../../util/pathutil.cjs' import * as urlutil from '../../util/urlutil.js' import lifecycle from '../../util/lifecycle.js' import rateLimitConfig from '../ratelimit/index.js' +import {ONE_DAY} from '../../util/apiutil.js' export default (function(options) { var log = logger.createLogger('auth-ldap') var app = express() @@ -89,7 +90,7 @@ export default (function(options) { } , secret: options.secret , header: { - exp: Date.now() + 24 * 3600 + exp: Date.now() + ONE_DAY } }) res.status(200) diff --git a/lib/units/auth/mock.js b/lib/units/auth/mock.js index de7c28797..53d24de14 100644 --- a/lib/units/auth/mock.js +++ b/lib/units/auth/mock.js @@ -15,6 +15,7 @@ import * as pathutil from '../../util/pathutil.cjs' import * as urlutil from '../../util/urlutil.js' import lifecycle from '../../util/lifecycle.js' import rateLimitConfig from '../ratelimit/index.js' +import {ONE_DAY} from '../../util/apiutil.js' export default (function(options) { var log = logger.createLogger('auth-mock') var app = express() @@ -108,7 +109,7 @@ export default (function(options) { } , secret: options.secret , header: { - exp: Date.now() + 24 * 3600 + exp: Date.now() + ONE_DAY } }) res.status(200) diff --git a/lib/units/auth/oauth2/index.js b/lib/units/auth/oauth2/index.js index b630b9118..f266eeef2 100644 --- a/lib/units/auth/oauth2/index.js +++ b/lib/units/auth/oauth2/index.js @@ -8,6 +8,7 @@ import * as jwtutil from '../../../util/jwtutil.js' import Strategy from './strategy.js' import rateLimitConfig from '../../ratelimit/index.js' import * as dbapi from '../../../db/api.js' +import {ONE_DAY} from '../../../util/apiutil.js' export default (function(options) { var log = logger.createLogger('auth-oauth2') var app = express() @@ -65,7 +66,7 @@ export default (function(options) { } , secret: options.secret , header: { - exp: Date.now() + 24 * 3600 + exp: Date.now() + ONE_DAY } }) })) diff --git a/lib/units/auth/saml2.js b/lib/units/auth/saml2.js index ba7c1bc2b..6480b00d8 100644 --- a/lib/units/auth/saml2.js +++ b/lib/units/auth/saml2.js @@ -11,6 +11,7 @@ import * as urlutil from '../../util/urlutil.js' import * as jwtutil from '../../util/jwtutil.js' import rateLimitConfig from '../ratelimit/index.js' import * as dbapi from '../../db/api.js' +import {ONE_DAY} from '../../util/apiutil.js' var SamlStrategy = {Strategy: passportSaml}.Strategy export default (function(options) { var log = logger.createLogger('auth-saml2') @@ -74,7 +75,7 @@ export default (function(options) { } , secret: options.secret , header: { - exp: Date.now() + 24 * 3600 + exp: Date.now() + ONE_DAY } }) })) diff --git a/lib/util/jwtutil.js b/lib/util/jwtutil.js index 2eb9c055b..c9560d4a4 100644 --- a/lib/util/jwtutil.js +++ b/lib/util/jwtutil.js @@ -1,11 +1,13 @@ import assert from 'assert' import * as jws from 'jws' import _ from 'lodash' +import {ONE_MONTH} from './apiutil.js' export const encode = function(options) { assert.ok(options.payload, 'payload required') assert.ok(options.secret, 'secret required') let header = { alg: 'HS256' + , exp: Date.now() + ONE_MONTH } if (options.header) { header = _.merge(header, options.header)