accessTokenNeedsRefresh reports whether the credential's access token has expired or falls within refreshExpiryLeeway of expiring as of now. A credential with no recorded expiry is treated as needing a refresh, since gh cannot prove the token is still valid. A debug lifetime override is anchored at
(credential gh.Credential, now time.Time)
| 367 | // of expiring as of now. A credential with no recorded expiry is treated as needing a refresh, since gh cannot prove |
| 368 | // the token is still valid. A debug lifetime override is anchored at the token's original issuance. |
| 369 | func accessTokenNeedsRefresh(credential gh.Credential, now time.Time) bool { |
| 370 | if credential.ExpiresAt == nil { |
| 371 | return true |
| 372 | } |
| 373 | expiresAt := *credential.ExpiresAt |
| 374 | if lifetime, ok := debug.Config().AccessTokenExpiresIn.Value(); ok { |
| 375 | issuedAt := credential.ExpiresAt.Add(-time.Duration(credential.ExpiresIn) * time.Second) |
| 376 | expiresAt = issuedAt.Add(lifetime) |
| 377 | } |
| 378 | return !now.Add(refreshExpiryLeeway).Before(expiresAt) |
| 379 | } |
| 380 | |
| 381 | // simulateRefreshTokenExpired simulates refresh token expiry when a debug lifetime override is set. |
| 382 | // The override is anchored at issuance, computed from the stored expiry and lifetime. |
no test coverage detected