auth

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 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 Endpoints

type Endpoints struct {
	APIKey string
	APIURL string
	AppURL string
}

Endpoints holds the API credentials and URLs from session options.

type Info

type Info struct {
	LoginToken   string
	OrgID        string
	OrgName      string
	APIKey       string
	APIURL       string
	ProxyURL     string
	AppURL       string
	AppPublicURL string
	LoggedIn     bool
}

Info holds authentication information

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
	// 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
}

Options contains options for the Login function

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.

func NewTestSession

func NewTestSession(info *Info, done chan struct{}, 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) Close

func (s *Session) Close()

Close cancels the background login goroutine.

func (*Session) Endpoints

func (s *Session) Endpoints() Endpoints

Endpoints returns the API credentials and URLs. If login has completed, returns values from Info (which may be updated by the server). Otherwise, falls back to the original Options. This is always available immediately, no blocking required.

func (*Session) Info

func (s *Session) Info() (bool, *Info)

Info returns current auth info (non-blocking). Returns (ok=true, info) if login succeeded. Returns (ok=false, nil) if login is in progress or failed.

func (*Session) Login

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

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

func (*Session) OrgName

func (s *Session) OrgName() string

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

Jump to

Keyboard shortcuts

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