MCPcopy Create free account
hub / github.com/cli/cli / accessTokenNeedsRefresh

Function accessTokenNeedsRefresh

internal/config/refreshable.go:370–380  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 4

ConfigFunction · 0.92
ValueMethod · 0.80
DurationMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected