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)
| 684 | // credential survived. A successful delete is verified by re-reading, because a dismissed Secret Service prompt reports |
| 685 | // success although nothing was deleted. |
| 686 | func (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 |
no test coverage detected