Documentation
¶
Overview ¶
Package githubauth owns GitHub.com device authorization and credentials.
Index ¶
- Constants
- Variables
- func ServeCredentialHelper(ctx context.Context, input io.Reader, output io.Writer) error
- type Credential
- type Device
- type Manager
- func (m *Manager) AccountForToken(token string) int64
- func (m *Manager) Cancel(ctx context.Context, id string) error
- func (m *Manager) Disconnect(ctx context.Context) error
- func (m *Manager) Health() error
- func (m *Manager) IdentityContext(ctx context.Context) (context.Context, func())
- func (m *Manager) ObserveResponse(token string, status int, headers http.Header)
- func (m *Manager) Organizations(ctx context.Context, token string, refresh bool) (OrganizationAccess, error)
- func (m *Manager) Poll(ctx context.Context, id string) (Status, error)
- func (m *Manager) Revision() uint64
- func (m *Manager) Start(ctx context.Context, workflow bool) (Device, error)
- func (m *Manager) Status(ctx context.Context) (Status, error)
- func (m *Manager) Token(ctx context.Context) (token string, returnedErr error)
- func (m *Manager) WithIdentity(ctx context.Context, publish func() error) error
- type Options
- type OrganizationAccess
- type ProcessStore
- type Status
- type Store
Constants ¶
const ApprovalURL = "https://github.com/settings/connections/applications/" + ClientID
ApprovalURL is the OAuth App's page in a member's GitHub settings, where they can ask an organization's owners to approve it.
const ClientID = "Ov23liFSMjrhof9WQlOi"
const Scopes = "repo read:org"
Scopes is what every sign-in requests. WorkflowScope is added only when the person asks for it, since it lets the token change GitHub Actions workflows.
const WorkflowScope = "workflow"
Variables ¶
var ErrNotConnected = errors.New("GitHub is not connected")
var ErrPermissions = errors.New("check repository access and GitHub authorization permissions")
var ErrReconnect = errors.New("GitHub authorization expired or was revoked; reconnect GitHub")
var ErrRequest = errors.New("GitHub authentication request failed; try again")
var ErrSSO = errors.New("authorize baum for your organization's GitHub SSO and retry")
var ErrScopes = errors.New("GitHub authorization requires repo and read:org access")
var ErrStore = errors.New("GitHub credential store unavailable; unlock your operating system credential store and try again")
Functions ¶
func ServeCredentialHelper ¶
ServeCredentialHelper is only for the hidden CLI helper. The native store runs synchronously here; ProcessStore owns this process's deadline and waits for termination before releasing its caller's serialization lock.
Types ¶
type Credential ¶
type Credential struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt int64 `json:"expires_at,omitempty"`
RefreshExpiresAt int64 `json:"refresh_expires_at,omitempty"`
Login string `json:"login"`
ID int64 `json:"id"`
// Workflow records that GitHub reported the workflow scope for this token.
Workflow bool `json:"workflow,omitempty"`
}
Credential is daemon-only state and must never be exposed by a public API. JSON is reserved for persistence in the operating system credential store.
func (Credential) GoString ¶
func (Credential) GoString() string
func (Credential) String ¶
func (Credential) String() string
String and GoString keep routine diagnostics from disclosing credentials.
type Device ¶
type Device struct {
ID string `json:"id"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
ExpiresAt time.Time `json:"expires_at"`
Interval int `json:"interval"`
// Workflow is whether this sign-in requests workflow access.
Workflow bool `json:"workflow,omitempty"`
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager serializes credential refresh, persistence and account replacement. Poll performs at most one exchange; callers can poll freely without exceeding GitHub's requested interval. Only one device authorization is active at a time.
func NewWithOptions ¶
func (*Manager) AccountForToken ¶
AccountForToken identifies only the credential most recently issued by Token. A late lookup for an older token never inherits the replacement account ID.
func (*Manager) IdentityContext ¶
IdentityContext cancels evidence work when the selected account changes. Token refresh does not cancel work because it retains the same identity.
func (*Manager) ObserveResponse ¶
ObserveResponse ignores late failures for a credential no longer in use. Upstream bodies and header values are never retained or exposed.
func (*Manager) Organizations ¶ added in v0.2.0
func (m *Manager) Organizations(ctx context.Context, token string, refresh bool) (OrganizationAccess, error)
Organizations compares the person's active organization memberships (`GET /user/memberships/orgs`) with the organizations GitHub lets an OAuth app token operate on (`GET /user/orgs`). Both need only the `read:org` scope the sign-in already holds. GitHub documents the second list as limited to organizations the authorization allows acting on, so a member of an organization that has not approved the app appears only in the first. Results are cached for five minutes per token; refresh asks again.
func (*Manager) Start ¶
Start begins a device sign-in. workflow adds the workflow scope, which only merges of pull requests that change GitHub Actions workflows need.
func (*Manager) Token ¶
Token returns the access token to use now. A token already read is served from memory without the manager's lock or the credential store; the store is read again only after the cache expires or is dropped (sign-out, account change, save, refresh, or a 401 from GitHub). Callers that miss together queue on the lock, and the first one's read fills the cache for the rest, so one helper launch serves them all.
type Options ¶
type Options struct{ Transport http.RoundTripper }
type OrganizationAccess ¶ added in v0.2.0
type OrganizationAccess struct {
Hidden []string `json:"hidden"`
ApprovalURL string `json:"approval_url"`
}
OrganizationAccess lists the organizations the signed-in person belongs to but this authorization cannot reach, which is how GitHub shows one that restricts OAuth app access until an owner approves the app. The list is best effort: it is empty when GitHub could not be asked.
type ProcessStore ¶
type ProcessStore struct{ Executable string }
ProcessStore bounds native credential-store prompts by running them in a helper process. Secrets travel only through private pipes, never argv or env. Every operation waits for the helper to exit before returning, so cancellation cannot leave a detached save racing a later disconnect.
func (ProcessStore) Load ¶
func (s ProcessStore) Load(ctx context.Context) (Credential, error)
func (ProcessStore) Save ¶
func (s ProcessStore) Save(ctx context.Context, c Credential) error