I’m setting up a Jenkins job in Kotlin to sync user data, but the access token from /api/v2/oauth/token expires way too fast. The default grant type gives me a short-lived token, and refreshing it inside the script feels messy. I need something that lasts for the entire build pipeline, maybe a few hours. Is there a way to get a long-lived token via code without manual intervention? I’ve tried setting x-gc-accepted-version but that didn’t change the expiry. Here’s the curl command I’m using for testing:
curl -X POST 'https://{{env}}.mygen.com/api/v2/oauth/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id={{clientId}}&client_secret={{secret}}'
The response JSON looks standard:
{
"access_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 7200
}
7200 seconds is two hours, which is actually okay for most builds, but if the job hangs or retries, it fails with 401 Unauthorized. I can’t just hardcode a refresh loop in the Kotlin client without adding significant complexity. The docs mention service accounts, but I’m not seeing a specific API parameter to extend the TTL. Am I missing a header? Or is there a different endpoint for CI/CD tokens? The platform SDK handles refresh automatically, but I’m using raw HTTP calls for this specific pipeline step to keep dependencies low. It’s annoying to debug 401 errors in the middle of a night build.