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

Function accessTokenNeedsRefresh

internal/config/refreshable.go:369–379  ·  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

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.
369func 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.

Callers 1

Calls 4

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

Tested by

no test coverage detected