Documentation
¶
Overview ¶
Package auth provides OAuth authentication for HEY.
Index ¶
- type Credentials
- type LoginOptions
- type Manager
- func (m *Manager) AccessToken(ctx context.Context) (string, error)
- func (m *Manager) AuthenticateRequest(ctx context.Context, req *http.Request) error
- func (m *Manager) CredentialKey() string
- func (m *Manager) GetStore() *Store
- func (m *Manager) IsAuthenticated() bool
- func (m *Manager) Login(ctx context.Context, opts LoginOptions) error
- func (m *Manager) LoginWithCookie(cookie string) error
- func (m *Manager) LoginWithToken(token string) error
- func (m *Manager) Logout() error
- func (m *Manager) OnCredentialCleared(fn func())
- func (m *Manager) Refresh(ctx context.Context) error
- type OAuthToken
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
type Credentials struct {
AccessToken string `json:"access_token"` //nolint:gosec // G117: legitimate credential field
RefreshToken string `json:"refresh_token"` //nolint:gosec // G117: legitimate credential field
ExpiresAt int64 `json:"expires_at"`
OAuthType string `json:"oauth_type"`
TokenEndpoint string `json:"token_endpoint"`
SessionCookie string `json:"session_cookie,omitempty"`
}
Credentials holds OAuth tokens and metadata.
type LoginOptions ¶
type LoginOptions struct {
NoBrowser bool
// Logger receives login progress messages (browser hand-off, the
// authorization URL, waiting notice). Nil keeps the default os.Stderr
// output unchanged. Messages may span multiple lines.
Logger func(msg string)
}
LoginOptions configures the login flow.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles OAuth authentication.
func NewManager ¶
NewManager creates a new auth manager.
func (*Manager) AccessToken ¶
AccessToken returns a valid access token, refreshing if needed. If HEY_TOKEN env var is set, it's used directly.
func (*Manager) AuthenticateRequest ¶
AuthenticateRequest sets the appropriate auth header on an HTTP request. Uses Bearer token if available, otherwise falls back to session cookie.
func (*Manager) CredentialKey ¶
CredentialKey returns the base URL used as the credential storage key.
func (*Manager) IsAuthenticated ¶
IsAuthenticated checks if there are valid credentials.
func (*Manager) Login ¶
func (m *Manager) Login(ctx context.Context, opts LoginOptions) error
Login initiates the browser-based OAuth login flow with PKCE.
func (*Manager) LoginWithCookie ¶
LoginWithCookie stores a session cookie.
func (*Manager) LoginWithToken ¶
LoginWithToken stores a pre-provided bearer token.
func (*Manager) OnCredentialCleared ¶ added in v1.5.0
func (m *Manager) OnCredentialCleared(fn func())
OnCredentialCleared registers what to run when the manager clears a credential on its own — today, when the server has refused the refresh token. It does not run for Logout, whose callers clear the cache themselves, and not when the store refused the deletion, because the credential is then still there to be used.
type OAuthToken ¶
type OAuthToken struct {
AccessToken string `json:"access_token"` //nolint:gosec // G117: legitimate OAuth field
RefreshToken string `json:"refresh_token"` //nolint:gosec // G117: legitimate OAuth field
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in"`
ExpiresAt time.Time `json:"-"`
}
OAuthToken represents the token response from the HEY OAuth server.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store handles credential storage, preferring system keychain.
func NewStore ¶
NewStore creates a credential store. Keyring availability is probed lazily on first credential operation, not at construction time.
func (*Store) InstallID ¶ added in v1.4.0
InstallID identifies this install to HEY as a device, minting the identifier on first use. It lives beside the credentials rather than in them: a device outlasts a logout, and HEY alerts on a sign-in from a device it hasn't seen.
func (*Store) Load ¶
func (s *Store) Load(origin string) (*Credentials, error)
Load retrieves credentials for the given origin.
func (*Store) MigrateToKeyring ¶
MigrateToKeyring migrates credentials from file to keyring.
func (*Store) Save ¶
func (s *Store) Save(origin string, creds *Credentials) error
Save stores credentials for the given origin.
func (*Store) UsingKeyring ¶
UsingKeyring returns true if the store is using the system keyring.