PR fix suggestions

This commit is contained in:
carlosmonastyrski
2025-04-22 14:25:52 -03:00
parent 7d4f223174
commit f08de1599d
14 changed files with 29 additions and 29 deletions
@@ -31,6 +31,8 @@ export const getAzureClientSecretsConnectionListItem = () => {
};
};
const EXPIRATION_TIME = 300000;
export const getAzureConnectionAccessToken = async (
connectionId: string,
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "updateById">,
@@ -62,9 +64,10 @@ export const getAzureConnectionAccessToken = async (
})) as TAzureClientSecretsConnectionCredentials;
const { expiresAt, refreshToken } = credentials;
const currentTime = Date.now();
// get new token if expired or less than 5 minutes until expiry
if (Date.now() < expiresAt - 300000) {
if (currentTime < expiresAt - EXPIRATION_TIME) {
return credentials.accessToken;
}
@@ -82,7 +85,7 @@ export const getAzureConnectionAccessToken = async (
const updatedCredentials = {
...credentials,
accessToken: data.access_token,
expiresAt: Date.now() + data.expires_in * 1000,
expiresAt: currentTime + data.expires_in * 1000,
refreshToken: data.refresh_token
};
@@ -102,6 +105,10 @@ export const validateAzureClientSecretsConnectionCredentials = async (config: TA
const { INF_APP_CONNECTION_AZURE_CLIENT_ID, INF_APP_CONNECTION_AZURE_CLIENT_SECRET, SITE_URL } = getConfig();
if (!SITE_URL) {
throw new InternalServerError({ message: "SITE_URL env var is required to complete Azure OAuth flow" });
}
if (!INF_APP_CONNECTION_AZURE_CLIENT_ID || !INF_APP_CONNECTION_AZURE_CLIENT_SECRET) {
throw new InternalServerError({
message: `Azure ${getAppConnectionMethodName(method)} environment variables have not been configured`