From 87ac723fcb017e8138b67d1b88ff1c8211e2b0e4 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 13 Mar 2025 01:45:49 +0530 Subject: [PATCH 1/2] feat: resolved renew token not renewing --- .../identity-access-token-service.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/src/services/identity-access-token/identity-access-token-service.ts b/backend/src/services/identity-access-token/identity-access-token-service.ts index 47d1791d2..a51d80e41 100644 --- a/backend/src/services/identity-access-token/identity-access-token-service.ts +++ b/backend/src/services/identity-access-token/identity-access-token-service.ts @@ -78,9 +78,7 @@ export const identityAccessTokenServiceFactory = ({ const renewAccessToken = async ({ accessToken }: TRenewAccessTokenDTO) => { const appCfg = getConfig(); - const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as JwtPayload & { - identityAccessTokenId: string; - }; + const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as TIdentityAccessTokenJwtPayload; if (decodedToken.authTokenType !== AuthTokenType.IDENTITY_ACCESS_TOKEN) { throw new BadRequestError({ message: "Only identity access tokens can be renewed" }); } @@ -127,7 +125,23 @@ export const identityAccessTokenServiceFactory = ({ accessTokenLastRenewedAt: new Date() }); - return { accessToken, identityAccessToken: updatedIdentityAccessToken }; + const renewedToken = jwt.sign( + { + identityId: decodedToken.identityId, + clientSecretId: decodedToken.clientSecretId, + identityAccessTokenId: decodedToken.identityAccessTokenId, + authTokenType: AuthTokenType.IDENTITY_ACCESS_TOKEN + } as TIdentityAccessTokenJwtPayload, + appCfg.AUTH_SECRET, + // akhilmhdh: for non-expiry tokens you should not even set the value, including undefined. Even for undefined jsonwebtoken throws error + Number(identityAccessToken.accessTokenTTL) === 0 + ? undefined + : { + expiresIn: Number(identityAccessToken.accessTokenTTL) + } + ); + + return { accessToken: renewedToken, identityAccessToken: updatedIdentityAccessToken }; }; const revokeAccessToken = async (accessToken: string) => { From 02153ffb32c178bc23fd38c7da4c474330fbcd9c Mon Sep 17 00:00:00 2001 From: = Date: Thu, 13 Mar 2025 19:41:33 +0530 Subject: [PATCH 2/2] fix: resolved create and update failing for service token --- backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts index 8e1de2d91..0abf02aaa 100644 --- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts +++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts @@ -94,7 +94,7 @@ export const fnSecretBulkInsert = async ({ ); const userActorId = actor && actor.type === ActorType.USER ? actor.actorId : undefined; - const identityActorId = actor && actor.type !== ActorType.USER ? actor.actorId : undefined; + const identityActorId = actor && actor.type === ActorType.IDENTITY ? actor.actorId : undefined; const actorType = actor?.type || ActorType.PLATFORM; const newSecrets = await secretDAL.insertMany( @@ -182,7 +182,7 @@ export const fnSecretBulkUpdate = async ({ actor }: TFnSecretBulkUpdate) => { const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined; - const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined; + const identityActorId = actor && actor?.type === ActorType.IDENTITY ? actor?.actorId : undefined; const actorType = actor?.type || ActorType.PLATFORM; const sanitizedInputSecrets = inputSecrets.map(