| 515 | } |
| 516 | |
| 517 | func (c *AuthConfig) login(hostname, username, token, gitProtocol string, secureStorage bool) (bool, error) { |
| 518 | // In this section we set up the users config |
| 519 | var setErr error |
| 520 | if secureStorage { |
| 521 | // Try to set the token for this user in the encrypted storage for later switching |
| 522 | setErr = keyring.Set(keyringServiceName(hostname), username, token) |
| 523 | if setErr == nil { |
| 524 | // Clean up the previous oauth_token from the config file, if there were one |
| 525 | _ = c.cfg.Remove([]string{hostsKey, hostname, usersKey, username, oauthTokenKey}) |
| 526 | } |
| 527 | } |
| 528 | insecureStorageUsed := false |
| 529 | if !secureStorage || setErr != nil { |
| 530 | // And set the oauth token under the user for later switching |
| 531 | c.cfg.Set([]string{hostsKey, hostname, usersKey, username, oauthTokenKey}, token) |
| 532 | insecureStorageUsed = true |
| 533 | } |
| 534 | |
| 535 | // Remove any refreshable credential for this user so the non-refreshable and refreshable forms never coexist. This |
| 536 | // mirrors loginRefreshable, which removes the non-expiring credential when storing a refreshable one. Without it, |
| 537 | // setActiveCredential keeps resolving the stale refreshable record as active and never copies the new |
| 538 | // non-refreshable token into the host-level slot, which also leaves go-gh extensions unable to read a token. |
| 539 | if err := c.purgeRefreshableForLogin(hostname, username); err != nil { |
| 540 | return insecureStorageUsed, err |
| 541 | } |
| 542 | |
| 543 | return insecureStorageUsed, c.completeLogin(hostname, username, gitProtocol) |
| 544 | } |
| 545 | |
| 546 | // completeLogin sets the host git protocol, ensures the user entry is persisted, and activates the user. It is shared |
| 547 | // by Login and LoginRefreshable once the credential has been stored. |