Skip to content

Commit de7e92c

Browse files
authored
Merge pull request #3236 from akhilmhdh/fix/renew-token
Resolved renew token not renewing
2 parents 522d81a + 87ac723 commit de7e92c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

backend/src/services/identity-access-token/identity-access-token-service.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export const identityAccessTokenServiceFactory = ({
7878
const renewAccessToken = async ({ accessToken }: TRenewAccessTokenDTO) => {
7979
const appCfg = getConfig();
8080

81-
const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as JwtPayload & {
82-
identityAccessTokenId: string;
83-
};
81+
const decodedToken = jwt.verify(accessToken, appCfg.AUTH_SECRET) as TIdentityAccessTokenJwtPayload;
8482
if (decodedToken.authTokenType !== AuthTokenType.IDENTITY_ACCESS_TOKEN) {
8583
throw new BadRequestError({ message: "Only identity access tokens can be renewed" });
8684
}
@@ -127,7 +125,23 @@ export const identityAccessTokenServiceFactory = ({
127125
accessTokenLastRenewedAt: new Date()
128126
});
129127

130-
return { accessToken, identityAccessToken: updatedIdentityAccessToken };
128+
const renewedToken = jwt.sign(
129+
{
130+
identityId: decodedToken.identityId,
131+
clientSecretId: decodedToken.clientSecretId,
132+
identityAccessTokenId: decodedToken.identityAccessTokenId,
133+
authTokenType: AuthTokenType.IDENTITY_ACCESS_TOKEN
134+
} as TIdentityAccessTokenJwtPayload,
135+
appCfg.AUTH_SECRET,
136+
// akhilmhdh: for non-expiry tokens you should not even set the value, including undefined. Even for undefined jsonwebtoken throws error
137+
Number(identityAccessToken.accessTokenTTL) === 0
138+
? undefined
139+
: {
140+
expiresIn: Number(identityAccessToken.accessTokenTTL)
141+
}
142+
);
143+
144+
return { accessToken: renewedToken, identityAccessToken: updatedIdentityAccessToken };
131145
};
132146

133147
const revokeAccessToken = async (accessToken: string) => {

0 commit comments

Comments
 (0)