auth

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accounts added in v0.10.0

func Accounts() (logins []string, current string, err error)

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

func DeleteAccount(login string) error

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 OpenBrowser(url string) error

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

type Client struct {
	Clock clock.Clock
}

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 DeviceAuthorization struct {
	UserCode        string
	VerificationURI string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL