diff --git a/App/FeatureSet/Identity/API/Authentication.ts b/App/FeatureSet/Identity/API/Authentication.ts index 7970ae113f..78c4414ffa 100644 --- a/App/FeatureSet/Identity/API/Authentication.ts +++ b/App/FeatureSet/Identity/API/Authentication.ts @@ -182,10 +182,12 @@ router.post( savedUser.id! ); - const token: string = JSONWebToken.sign( - savedUser, - OneUptimeDate.getSecondsInDays(new PositiveNumber(30)) - ); + const token: string = JSONWebToken.sign({ + data: savedUser, + expiresInSeconds: OneUptimeDate.getSecondsInDays( + new PositiveNumber(30) + ), + }); // Set a cookie with token. CookieUtil.setCookie(res, CookieUtil.getUserTokenKey(), token, { @@ -573,10 +575,12 @@ router.post( alreadySavedUser.password.toString() === user.password!.toString() ) { - const token: string = JSONWebToken.sign( - alreadySavedUser, - OneUptimeDate.getSecondsInDays(new PositiveNumber(30)) - ); + const token: string = JSONWebToken.sign({ + data: alreadySavedUser, + expiresInSeconds: OneUptimeDate.getSecondsInDays( + new PositiveNumber(30) + ), + }); // Set a cookie with token. CookieUtil.setCookie( diff --git a/App/FeatureSet/Identity/API/Reseller.ts b/App/FeatureSet/Identity/API/Reseller.ts index 2247796c96..50cb532403 100644 --- a/App/FeatureSet/Identity/API/Reseller.ts +++ b/App/FeatureSet/Identity/API/Reseller.ts @@ -62,10 +62,10 @@ router.post( // if found then generate a token and return it. - const token: string = JSONWebToken.sign( - { resellerId: resellerId }, - OneUptimeDate.getDayInSeconds(365) - ); + const token: string = JSONWebToken.sign({ + data: { resellerId: resellerId }, + expiresInSeconds: OneUptimeDate.getDayInSeconds(365), + }); return Response.sendJsonObjectResponse(req, res, { access: token, diff --git a/App/FeatureSet/Identity/API/SSO.ts b/App/FeatureSet/Identity/API/SSO.ts index 4958b2d216..04ac3cdf9c 100644 --- a/App/FeatureSet/Identity/API/SSO.ts +++ b/App/FeatureSet/Identity/API/SSO.ts @@ -367,15 +367,17 @@ const loginUserWithSso: LoginUserWithSsoFunction = async ( req.params['projectId'] as string ); - const token: string = JSONWebToken.sign( - { + const token: string = JSONWebToken.sign({ + data: { userId: alreadySavedUser.id!, projectId: projectId, email: email, isMasterAdmin: false, }, - OneUptimeDate.getSecondsInDays(new PositiveNumber(30)) - ); + expiresInSeconds: OneUptimeDate.getSecondsInDays( + new PositiveNumber(30) + ), + }); // Refresh Permissions for this user here. await AccessTokenService.refreshUserAllPermissions( diff --git a/App/FeatureSet/Identity/API/StatusPageAuthentication.ts b/App/FeatureSet/Identity/API/StatusPageAuthentication.ts index b298794d7c..7097da14bd 100644 --- a/App/FeatureSet/Identity/API/StatusPageAuthentication.ts +++ b/App/FeatureSet/Identity/API/StatusPageAuthentication.ts @@ -389,10 +389,12 @@ router.post( }); if (alreadySavedUser) { - const token: string = JSONWebToken.sign( - alreadySavedUser, - OneUptimeDate.getSecondsInDays(new PositiveNumber(30)) - ); + const token: string = JSONWebToken.sign({ + data: alreadySavedUser, + expiresInSeconds: OneUptimeDate.getSecondsInDays( + new PositiveNumber(30) + ), + }); CookieUtil.setCookie( res, diff --git a/App/FeatureSet/Identity/API/StatusPageSSO.ts b/App/FeatureSet/Identity/API/StatusPageSSO.ts index e1014c0378..5a6c864bc0 100644 --- a/App/FeatureSet/Identity/API/StatusPageSSO.ts +++ b/App/FeatureSet/Identity/API/StatusPageSSO.ts @@ -270,10 +270,12 @@ router.post( }); } - const token: string = JSONWebToken.sign( - alreadySavedUser, - OneUptimeDate.getSecondsInDays(new PositiveNumber(30)) - ); + const token: string = JSONWebToken.sign({ + data: alreadySavedUser, + expiresInSeconds: OneUptimeDate.getSecondsInDays( + new PositiveNumber(30) + ), + }); CookieUtil.setCookie( res, diff --git a/CommonServer/Utils/JsonWebToken.ts b/CommonServer/Utils/JsonWebToken.ts index 096b5c0f50..67c081f25c 100644 --- a/CommonServer/Utils/JsonWebToken.ts +++ b/CommonServer/Utils/JsonWebToken.ts @@ -11,15 +11,17 @@ import StatusPagePrivateUser from 'Model/Models/StatusPagePrivateUser'; import JSONFunctions from 'Common/Types/JSONFunctions'; class JSONWebToken { - public static sign( + public static sign(props: { data: | JSONWebTokenData | User | StatusPagePrivateUser | string - | JSONObject, - expiresInSeconds: number - ): string { + | JSONObject; + expiresInSeconds: number; + }): string { + const { data, expiresInSeconds } = props; + let jsonObj: JSONObject; if (typeof data === 'string') {