auth

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth provides authentication functionality for the Braintrust SDK.

Index

Constants

View Source
const (
	// TestAPIKey is a special API key used for testing
	TestAPIKey = "___TEST_API_KEY___"
	// DefaultAppURL is the default Braintrust app URL
	DefaultAppURL = "https://www.braintrust.dev"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIInfo added in v0.1.0

type APIInfo struct {
	APIKey string
	APIURL string
}

APIInfo contains API credentials and endpoint information.

type APIKeyResolver added in v0.8.0

type APIKeyResolver interface {
	APIKey(context.Context) (string, bool)
}

APIKeyResolver resolves a Braintrust API key on demand.

type Options

type Options struct {
	// AppURL is the URL of the Braintrust app
	AppURL string
	// AppPublicURL is the public URL of the Braintrust app
	AppPublicURL string
	// APIURL is the URL of the Braintrust API
	APIURL string
	// APIKey is the API key to use
	APIKey string
	// APIKeyResolver resolves the API key when APIKey is not provided
	APIKeyResolver APIKeyResolver
	// OrgName is the name of a specific organization to connect to (optional)
	OrgName string
	// Logger is the logger to use (optional, defaults to noop logger)
	Logger logger.Logger
	// Client is the HTTPS client to use for login requests (optional)
	// If not provided, a default https.Client will be created
	// This is primarily used for testing with VCR
	Client *https.Client
}

Options contains options for the Login function

type Org added in v0.1.0

type Org struct {
	ID   string
	Name string
}

Org contains organization information.

type OrgInfo

type OrgInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	APIURL   string `json:"api_url"`
	ProxyURL string `json:"proxy_url"`
}

OrgInfo represents organization information from the login response

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session manages authentication and login state.

func NewSession

func NewSession(ctx context.Context, opts Options) (*Session, error)

NewSession creates a session and starts login with retry in the background. Returns an error if required fields (APIKey, AppURL) are missing. The context is used for the background login goroutine. If opts.Logger is nil, a noop logger is used. If opts.Client is nil, a default client will be created.

func NewTestSession

func NewTestSession(apiKey, orgID, orgName, apiURL, appURL, appPublicURL string, log logger.Logger) *Session

NewTestSession creates a static test session with hardcoded data. This is for use in test packages outside of internal/auth to avoid import cycles. This session does not make any network calls or start goroutines.

func (*Session) APIInfo added in v0.1.0

func (s *Session) APIInfo() APIInfo

APIInfo returns the API key and API URL. API key comes from config, API URL comes from server response (or default). Always available - falls back to config/defaults if login not complete.

func (*Session) AppPublicURL added in v0.1.0

func (s *Session) AppPublicURL() string

AppPublicURL returns the public app URL from config. Always available.

func (*Session) Close

func (s *Session) Close()

Close cancels the background login goroutine.

func (*Session) Login

func (s *Session) Login(ctx context.Context) error

Login blocks until login completes or context is cancelled. Returns error if login failed.

func (*Session) OrgInfo added in v0.1.0

func (s *Session) OrgInfo() Org

OrgInfo returns the organization ID and name from the server response. Returns empty strings if login hasn't completed yet.

func (*Session) OrgName

func (s *Session) OrgName() string

OrgName returns the organization name if available. Returns empty string if login hasn't completed yet.

func (*Session) ResolveAPIKey added in v0.8.0

func (s *Session) ResolveAPIKey(ctx context.Context) (string, bool)

ResolveAPIKey returns the configured API key or waits for the lazy resolver.

Jump to

Keyboard shortcuts

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