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

Method purgeNonExpiringForRefreshableLogin

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

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