auth

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package auth provides OAuth 2.1 authentication for Basecamp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientCredentials

type ClientCredentials struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret,omitempty"`
}

ClientCredentials holds OAuth client ID and secret.

type Credentials

type Credentials struct {
	AccessToken   string `json:"access_token"`
	RefreshToken  string `json:"refresh_token"`
	ExpiresAt     int64  `json:"expires_at"`
	Scope         string `json:"scope"`
	OAuthType     string `json:"oauth_type"` // "bc3" or "launchpad"
	TokenEndpoint string `json:"token_endpoint"`
	UserID        string `json:"user_id,omitempty"`
}

Credentials holds OAuth tokens and metadata.

type LoginOptions

type LoginOptions struct {
	Scope     string
	NoBrowser bool // If true, don't auto-open browser, just print URL

	// CallbackAddr is the address for the local OAuth callback server.
	// Default: "127.0.0.1:8976"
	CallbackAddr string

	// BrowserLauncher opens the authorization URL in a browser.
	// If nil, uses the default system browser launcher.
	BrowserLauncher func(url string) error

	// Logger receives status messages during the login flow.
	// If nil, messages are suppressed for headless/SDK use.
	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

func NewManager(cfg *config.Config, httpClient *http.Client) *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 BASECAMP_TOKEN env var is set, it's used directly without OAuth.

func (*Manager) CredentialKey

func (m *Manager) CredentialKey() string

CredentialKey returns the current credential storage key. This is exported for use in commands that need to display or lookup credentials.

func (*Manager) GetOAuthType

func (m *Manager) GetOAuthType() string

GetOAuthType returns the OAuth type for the current credential key ("bc3" or "launchpad").

func (*Manager) GetStore

func (m *Manager) GetStore() *Store

GetStore returns the credential store.

func (*Manager) GetUserID

func (m *Manager) GetUserID() string

GetUserID returns the stored user ID for the current credential key.

func (*Manager) IsAuthenticated

func (m *Manager) IsAuthenticated() bool

IsAuthenticated checks if there are valid credentials. Returns true if BASECAMP_TOKEN env var is set or if OAuth credentials exist.

func (*Manager) Login

func (m *Manager) Login(ctx context.Context, opts LoginOptions) error

Login initiates the OAuth login flow.

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.

func (*Manager) SetUserID

func (m *Manager) SetUserID(userID string) error

SetUserID stores the user ID for the current credential key.

func (*Manager) StoredAccessToken

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

StoredAccessToken returns a valid access token from the credential store, refreshing if needed. Unlike AccessToken, this ignores the BASECAMP_TOKEN environment variable and always uses stored OAuth credentials.

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.

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