()
| 278 | } |
| 279 | |
| 280 | const authenticate = async (): Promise<HttpClientHeaders> => { |
| 281 | logger.debug('authentication - enter') |
| 282 | // refresh if we have less than an hour left on the auth token |
| 283 | if (authenticationInfo && authenticationInfo.expires.getTime() < Date.now() + 60 * 60 * 1000) { |
| 284 | await refreshToken() |
| 285 | } |
| 286 | |
| 287 | // log in if we don't have authentication info or the refresh failed |
| 288 | if (!authenticationInfo || authenticationInfo.expires.getTime() < Date.now() + 59 * 60 * 1000) { |
| 289 | await login() |
| 290 | } |
| 291 | |
| 292 | if (authenticationInfo) { |
| 293 | return { Authorization: `Bearer ${authenticationInfo.accessToken}` } |
| 294 | } |
| 295 | |
| 296 | throw new Error('unable to obtain user credentials') |
| 297 | } |
| 298 | |
| 299 | return { |
| 300 | login, |
nothing calls this directly
no test coverage detected