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

Method credentialRotatedByPeer

internal/config/refreshable.go:616–631  ·  view source on GitHub ↗

credentialRotatedByPeer re-reads the user's stored refreshable credential after the server rejected rejectedRefreshToken, and returns it when its refresh token differs, which means another process (or a new login) replaced the credential. Each attempt reloads the configuration from disk first, so a

(hostname, username, rejectedRefreshToken string)

Source from the content-addressed store, hash-verified

614// hosts.yml by another process is observed, not just one written to the keyring. It must run under
615// withFreshConfigForRefresh, whose in-place reload contract it relies on.
616func (c *AuthConfig) credentialRotatedByPeer(hostname, username, rejectedRefreshToken string) (gh.Credential, bool) {
617 sleep := c.sleep
618 if sleep == nil {
619 sleep = time.Sleep
620 }
621 for _, delay := range refreshRejectionRecheckDelays {
622 sleep(delay)
623 // A failed reload still leaves the keyring readable, so carry on with the in-memory configuration.
624 _ = c.reload()
625 stored, _, err := c.refreshableForUser(hostname, username)
626 if err == nil && stored.RefreshToken != rejectedRefreshToken {
627 return stored, true
628 }
629 }
630 return gh.Credential{}, false
631}
632
633// warnRejectedKept warns that the server rejected the refresh token while gh did not hold the refresh lock, so the
634// stored credential was kept and the caller receives no token. Without the lock the rejection may only mean that a peer

Callers 1

Calls 3

reloadMethod · 0.95
refreshableForUserMethod · 0.95
sleepFunction · 0.85

Tested by

no test coverage detected