Running a headless Node script in GitHub Actions to pull audit logs. Using the genesys-cloud-purecloud-platform-client with client credentials. The token expires after an hour, so I’m wrapping the calls in a retry handler that checks the 401 status.
const client = PlatformClient.ApiClient.instance;
client.loginWithClientCredentials(clientId, clientSecret);
async function fetchWithRetry(endpoint, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const res = await client.get(endpoint);
return res;
} catch (err) {
if (err.status === 401 && i < maxRetries - 1) {
await client.loginWithClientCredentials(clientId, clientSecret);
continue;
}
throw err;
}
}
}
The issue is the loginWithClientCredentials call is blocking or timing out after a few refreshes in the container. The CI job fails with a network timeout on the auth endpoint. Is there a better way to handle token lifecycle in a long-running script without hammering the token endpoint? Or should I just generate a long-lived token manually and inject it as an env var? Feels risky to store that in the repo secrets.