auth

package
v0.0.0-...-1512c16 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package auth provides OAuth authentication for HEY.

Index

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

func NewManager(baseURL string, httpClient *http.Client, configDir string) *Manager

NewManager creates a new auth manager.

func (*Manager) AccessToken

func (m *Manager) AccessToken(ctx context.Context) (string, error)

AccessToken returns a valid access token, refreshing if needed. If HEY_TOKEN env var is set, it's used directly.

func (*Manager) AuthenticateRequest

func (m *Manager) AuthenticateRequest(ctx context.Context, req *http.Request) error

AuthenticateRequest sets the appropriate auth header on an HTTP request. Uses Bearer token if available, otherwise falls back to session cookie.

func (*Manager) CredentialKey

func (m *Manager) CredentialKey() string

CredentialKey returns the base URL used as the credential storage key.

func (*Manager) GetStore

func (m *Manager) GetStore() *Store

GetStore returns the credential store.

func (*Manager) IsAuthenticated

func (m *Manager) IsAuthenticated() bool

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

func (m *Manager) LoginWithCookie(cookie string) error

LoginWithCookie stores a session cookie.

func (*Manager) LoginWithToken

func (m *Manager) LoginWithToken(token string) error

LoginWithToken stores a pre-provided bearer token.

func (*Manager) Logout

func (m *Manager) Logout() error

Logout removes stored credentials.

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context) error

Refresh forces a token refresh.

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

func NewStore(fallbackDir string) *Store

NewStore creates a credential store. Keyring availability is probed lazily on first credential operation, not at construction time.

func (*Store) Delete

func (s *Store) Delete(origin string) error

Delete removes credentials for the given origin.

func (*Store) Load

func (s *Store) Load(origin string) (*Credentials, error)

Load retrieves credentials for the given origin.

func (*Store) MigrateToKeyring

func (s *Store) MigrateToKeyring() error

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

func (s *Store) UsingKeyring() bool

UsingKeyring returns true if the store is using the system keyring.

Jump to

Keyboard shortcuts

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