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

Method purgeNonExpiringForRefreshableLogin

internal/config/refreshable.go:216–228  ·  view source on GitHub ↗

purgeNonExpiringForRefreshableLogin removes any non-expiring credential for the user during a refreshable login so the two credential forms cannot coexist. The ordinary keyring is now resolved before the refreshable credential, so a surviving non-expiring token would outrank the freshly stored refre

(hostname, username string)

Source from the content-addressed store, hash-verified

214// present", so the check stays silent exactly where a delete error would be spurious. Only a token that genuinely
215// survives removal is surfaced.
216func (c *AuthConfig) purgeNonExpiringForRefreshableLogin(hostname, username string) error {
217 // Best-effort removal in both stores, matching login's symmetric cleanup.
218 _ = c.cfg.Remove([]string{hostsKey, hostname, usersKey, username, oauthTokenKey})
219 _ = keyringDelete(keyringServiceName(hostname), username)
220
221 if _, err := keyring.Get(keyringServiceName(hostname), username); err == nil {
222 return errors.New("could not remove the existing non-expiring credential, which would shadow this login")
223 }
224 if _, err := c.cfg.Get([]string{hostsKey, hostname, usersKey, username, oauthTokenKey}); err == nil {
225 return errors.New("could not remove the existing non-expiring credential, which would shadow this login")
226 }
227 return nil
228}
229
230// refreshableForUser returns the refreshable credential stored for the user along with whether it came from secure
231// storage. It prefers the secure keyring and falls back to the insecure configuration record, returning

Callers 1

loginRefreshableMethod · 0.95

Calls 4

GetFunction · 0.92
keyringServiceNameFunction · 0.70
RemoveMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected