Documentation
¶
Index ¶
- func Accounts() (logins []string, current string, err error)
- func DeleteAccount(login string) error
- func DeleteToken() error
- func OpenBrowser(url string) error
- func SaveToken(token *StoredToken) error
- func TokenKeyringEntry() (service, key string)
- func UseLatestAccount() error
- type Client
- type DeviceAuthorization
- type DevicePrompter
- type StoredToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accounts ¶ added in v0.10.0
Accounts lists the signed-in GitHub logins, the most recent sign-in last, and the one in use, "" when there is none. GITHUB_TOKEN is not an account.
func DeleteAccount ¶ added in v0.10.0
DeleteAccount signs out of the account login, or of the one in use when login is "". Signing out of no account is not an error.
func DeleteToken ¶
func DeleteToken() error
DeleteToken signs out of the account in use. The most recent remaining sign-in is used next.
func OpenBrowser ¶
func SaveToken ¶
func SaveToken(token *StoredToken) error
SaveToken adds the account, or replaces its token when it is already signed in, and makes it the account in use. The choice is written first, and put back if the keyring then fails, so a failed sign-in changes nothing.
Two sign-ins at the same moment, such as the CLI and the desktop app, may keep only one of the two accounts; signing in again adds the other.
func TokenKeyringEntry ¶ added in v0.10.0
func TokenKeyringEntry() (service, key string)
TokenKeyringEntry is the OS keyring entry of the GitHub token, which the Windows enbu.exe shares with WSL.
func UseLatestAccount ¶ added in v0.10.0
func UseLatestAccount() error
UseLatestAccount makes the most recent sign-in the account in use. Inside WSL the Windows enbu.exe signs in, so this data directory follows it here.
Types ¶
type Client ¶ added in v0.10.0
Client signs in to GitHub with the Device Flow: the user enters a code at github.com/login/device, so no callback server or broker is involved.
func (Client) Login ¶ added in v0.10.0
func (c Client) Login(ctx context.Context, prompt DevicePrompter) (*StoredToken, error)
Login shows prompt the code to enter, waits for the user to authorize it and saves the token.
type DeviceAuthorization ¶
type DevicePrompter ¶
type DevicePrompter func(DeviceAuthorization) error
type StoredToken ¶
type StoredToken struct {
AccessToken string `json:"access_token"`
Username string `json:"username"`
UserID int64 `json:"user_id"`
}
func LoadToken ¶
func LoadToken() (*StoredToken, error)
LoadToken returns GITHUB_TOKEN when it is set, otherwise the account in use.
func SwitchAccount ¶ added in v0.10.0
func SwitchAccount(login string) (*StoredToken, error)
SwitchAccount makes the signed-in account login the one in use in this data directory. The login is matched without regard to case, as GitHub does.