auth

package
v0.0.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultClientID     = "n3XETVLxuMMtXJg37Q"
	DefaultClientSecret = "uYuRebCD6XJegxfuPfTuAvah7hGQB7en"
)

Default OAuth consumer credentials embedded in the CLI binary. These are not secret — they identify the app, not the user. The security is in the user's browser-based authorization flow. This is the same pattern used by GitHub CLI (gh). Override with BB_CLIENT_ID / BB_CLIENT_SECRET env vars or --client-id / --client-secret flags.

Functions

func AuthorizeURL

func AuthorizeURL(clientID string, port int) string

AuthorizeURL builds the OAuth authorization URL.

func StartCallbackServer

func StartCallbackServer() (int, chan string, chan error, error)

StartCallbackServer starts an HTTP server on a random port to receive the OAuth callback. It returns the port, a channel that will receive the authorization code, and any error.

Types

type Credentials

type Credentials struct {
	Username string `json:"username"`
	APIToken string `json:"api_token,omitempty"`

	// OAuth fields
	AuthMethod   string `json:"auth_method,omitempty"` // "api_token" or "oauth"
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	ExpiresAt    int64  `json:"expires_at,omitempty"`
	ClientID     string `json:"client_id,omitempty"`
	ClientSecret string `json:"client_secret,omitempty"`
}

Credentials holds the authentication credentials.

func (*Credentials) IsOAuth

func (c *Credentials) IsOAuth() bool

IsOAuth returns true if the credentials use OAuth authentication.

type FileStore

type FileStore struct{}

FileStore implements Store using a JSON file on disk.

func NewFileStore

func NewFileStore() *FileStore

NewFileStore creates a new file-based credential store.

func (*FileStore) DeleteCredentials

func (f *FileStore) DeleteCredentials() error

DeleteCredentials removes the credentials file.

func (*FileStore) GetCredentials

func (f *FileStore) GetCredentials() (*Credentials, error)

GetCredentials reads credentials from the credentials file.

func (*FileStore) SetCredentials

func (f *FileStore) SetCredentials(creds *Credentials) error

SetCredentials writes credentials to the credentials file with 0600 permissions.

type Store

type Store interface {
	GetCredentials() (*Credentials, error)
	SetCredentials(creds *Credentials) error
	DeleteCredentials() error
}

Store is the interface for credential storage.

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
	Scopes       string `json:"scopes"`
}

TokenResponse holds the response from the OAuth token endpoint.

func ExchangeCode

func ExchangeCode(clientID, clientSecret, code string, port int) (*TokenResponse, error)

ExchangeCode exchanges an authorization code for tokens.

func RefreshAccessToken

func RefreshAccessToken(clientID, clientSecret, refreshToken string) (*TokenResponse, error)

RefreshAccessToken refreshes an expired access token.

Jump to

Keyboard shortcuts

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