3 const ONE_HOUR_MS = 60 * 60 * 1000;
5 function parseAccessTokenExpiresMsFromRes(resData) {
6 const createdAtSeconds = resData.created_at;
7 const expiresInSeconds = resData.expires_in;
8 // GitLab access tokens expire after 2 hours,
9 // https://docs.gitlab.com/14.10/ee/integration/oauth_provider.html
10 let accessTokenExpiresMs = Date.now() + 2 * ONE_HOUR_MS;
11 // But let's try to grab this info from the request if it exists instead as
12 // that behavior could change at any time.
13 if (createdAtSeconds && expiresInSeconds) {
14 accessTokenExpiresMs = 1000 * (createdAtSeconds + expiresInSeconds);
17 return accessTokenExpiresMs;
20 module.exports = parseAccessTokenExpiresMsFromRes;