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) 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
}
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.
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) 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.