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

Method removeCredentialForUser

internal/config/refreshable.go:686–709  ·  view source on GitHub ↗

removeCredentialForUser deletes every stored credential record for the user on the host, covering both the refreshable and the non-expiring forms in both the keyring and the insecure config, then writes the config. It intentionally leaves the active-user pointer and the rest of the host configuratio

(hostname, username string, secure bool)

Source from the content-addressed store, hash-verified

684// credential survived. A successful delete is verified by re-reading, because a dismissed Secret Service prompt reports
685// success although nothing was deleted.
686func (c *AuthConfig) removeCredentialForUser(hostname, username string, secure bool) error {
687 refreshableErr := keyringDelete(refreshableServiceName(hostname), username)
688 _ = keyringDelete(keyringServiceName(hostname), username)
689 _ = c.cfg.Remove(refreshablePath(hostname, username))
690 _ = c.cfg.Remove([]string{hostsKey, hostname, usersKey, username, oauthTokenKey})
691 if err := ghConfig.Write(c.cfg); err != nil {
692 return err
693 }
694 if !secure || errors.Is(refreshableErr, keyring.ErrNotFound) {
695 return nil
696 }
697 if refreshableErr != nil {
698 return refreshableErr
699 }
700 // Only a missing record confirms the removal; any other read error leaves it unconfirmed.
701 _, err := keyring.Get(refreshableServiceName(hostname), username)
702 if err == nil {
703 return errors.New("the credential remained in the keyring")
704 }
705 if errors.Is(err, keyring.ErrNotFound) {
706 return nil
707 }
708 return fmt.Errorf("could not confirm the credential was removed from the keyring: %w", err)
709}
710
711// persistRefreshedCredential writes a renewed refreshable credential back to the storage form it already lived in.
712// Refreshable credentials are resolved per-user via the active user key, so there is no host-level active copy to keep

Callers 1

Calls 7

GetFunction · 0.92
refreshableServiceNameFunction · 0.85
refreshablePathFunction · 0.85
keyringServiceNameFunction · 0.70
RemoveMethod · 0.65
WriteMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected