mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 13:27:46 +00:00
Patch identity ttl conversion
This commit is contained in:
@@ -35,12 +35,12 @@ export const identityAccessTokenServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ttl check
|
// ttl check
|
||||||
if (accessTokenTTL > 0) {
|
if (Number(accessTokenTTL) > 0) {
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
if (accessTokenLastRenewedAt) {
|
if (accessTokenLastRenewedAt) {
|
||||||
// access token has been renewed
|
// access token has been renewed
|
||||||
const accessTokenRenewed = new Date(accessTokenLastRenewedAt);
|
const accessTokenRenewed = new Date(accessTokenLastRenewedAt);
|
||||||
const ttlInMilliseconds = accessTokenTTL * 1000;
|
const ttlInMilliseconds = Number(accessTokenTTL) * 1000;
|
||||||
const expirationDate = new Date(accessTokenRenewed.getTime() + ttlInMilliseconds);
|
const expirationDate = new Date(accessTokenRenewed.getTime() + ttlInMilliseconds);
|
||||||
|
|
||||||
if (currentDate > expirationDate)
|
if (currentDate > expirationDate)
|
||||||
@@ -50,7 +50,7 @@ export const identityAccessTokenServiceFactory = ({
|
|||||||
} else {
|
} else {
|
||||||
// access token has never been renewed
|
// access token has never been renewed
|
||||||
const accessTokenCreated = new Date(accessTokenCreatedAt);
|
const accessTokenCreated = new Date(accessTokenCreatedAt);
|
||||||
const ttlInMilliseconds = accessTokenTTL * 1000;
|
const ttlInMilliseconds = Number(accessTokenTTL) * 1000;
|
||||||
const expirationDate = new Date(accessTokenCreated.getTime() + ttlInMilliseconds);
|
const expirationDate = new Date(accessTokenCreated.getTime() + ttlInMilliseconds);
|
||||||
|
|
||||||
if (currentDate > expirationDate)
|
if (currentDate > expirationDate)
|
||||||
@@ -61,9 +61,9 @@ export const identityAccessTokenServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// max ttl checks
|
// max ttl checks
|
||||||
if (accessTokenMaxTTL > 0) {
|
if (Number(accessTokenMaxTTL) > 0) {
|
||||||
const accessTokenCreated = new Date(accessTokenCreatedAt);
|
const accessTokenCreated = new Date(accessTokenCreatedAt);
|
||||||
const ttlInMilliseconds = accessTokenMaxTTL * 1000;
|
const ttlInMilliseconds = Number(accessTokenMaxTTL) * 1000;
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const expirationDate = new Date(accessTokenCreated.getTime() + ttlInMilliseconds);
|
const expirationDate = new Date(accessTokenCreated.getTime() + ttlInMilliseconds);
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ export const identityAccessTokenServiceFactory = ({
|
|||||||
message: "Failed to renew MI access token due to Max TTL expiration"
|
message: "Failed to renew MI access token due to Max TTL expiration"
|
||||||
});
|
});
|
||||||
|
|
||||||
const extendToDate = new Date(currentDate.getTime() + accessTokenTTL);
|
const extendToDate = new Date(currentDate.getTime() + Number(accessTokenTTL));
|
||||||
if (extendToDate > expirationDate)
|
if (extendToDate > expirationDate)
|
||||||
throw new UnauthorizedError({
|
throw new UnauthorizedError({
|
||||||
message: "Failed to renew MI access token past its Max TTL expiration"
|
message: "Failed to renew MI access token past its Max TTL expiration"
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ export const identityUaServiceFactory = ({
|
|||||||
if (!validClientSecretInfo) throw new UnauthorizedError();
|
if (!validClientSecretInfo) throw new UnauthorizedError();
|
||||||
|
|
||||||
const { clientSecretTTL, clientSecretNumUses, clientSecretNumUsesLimit } = validClientSecretInfo;
|
const { clientSecretTTL, clientSecretNumUses, clientSecretNumUsesLimit } = validClientSecretInfo;
|
||||||
if (clientSecretTTL > 0) {
|
if (Number(clientSecretTTL) > 0) {
|
||||||
const clientSecretCreated = new Date(validClientSecretInfo.createdAt);
|
const clientSecretCreated = new Date(validClientSecretInfo.createdAt);
|
||||||
const ttlInMilliseconds = clientSecretTTL * 1000;
|
const ttlInMilliseconds = Number(clientSecretTTL) * 1000;
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const expirationTime = new Date(clientSecretCreated.getTime() + ttlInMilliseconds);
|
const expirationTime = new Date(clientSecretCreated.getTime() + ttlInMilliseconds);
|
||||||
|
|
||||||
@@ -124,7 +124,10 @@ export const identityUaServiceFactory = ({
|
|||||||
} as TIdentityAccessTokenJwtPayload,
|
} as TIdentityAccessTokenJwtPayload,
|
||||||
appCfg.AUTH_SECRET,
|
appCfg.AUTH_SECRET,
|
||||||
{
|
{
|
||||||
expiresIn: identityAccessToken.accessTokenMaxTTL === 0 ? undefined : identityAccessToken.accessTokenMaxTTL
|
expiresIn:
|
||||||
|
Number(identityAccessToken.accessTokenMaxTTL) === 0
|
||||||
|
? undefined
|
||||||
|
: Number(identityAccessToken.accessTokenMaxTTL)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user