auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package auth issues and verifies caller API tokens without storing secrets.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("invalid or revoked API token")

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	AuthenticateRequest(*http.Request) (Principal, error)
}

type IssuedToken

type IssuedToken struct {
	KeyID  string
	Secret string
}

type PreparedToken

type PreparedToken struct {
	KeyID         string
	Secret        string
	PrincipalType PrincipalType
	SubjectID     string
}

func Prepare

func Prepare(principalType PrincipalType, subjectID string) (PreparedToken, error)

Prepare creates a credential without making it authenticatable. Callers can durably persist the returned secret before Activate commits its hash. This split is what makes external credential rotation recoverable across a crash.

type Principal

type Principal struct {
	Type      PrincipalType
	SubjectID string
	KeyID     string
}

type PrincipalType

type PrincipalType string
const (
	PrincipalCaller PrincipalType = "caller"
	PrincipalWorker PrincipalType = "worker"
)

type Service

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

func NewService

func NewService(store storeapi.TokenStore) *Service

func (*Service) Activate

func (service *Service) Activate(ctx context.Context, prepared PreparedToken) error

Activate commits a prepared credential. It is idempotent for the exact same key, secret, type, and subject so a journal can safely replay after a crash.

func (*Service) Authenticate

func (service *Service) Authenticate(ctx context.Context, secret string) (Principal, error)

func (*Service) AuthenticateRequest

func (service *Service) AuthenticateRequest(request *http.Request) (Principal, error)

AuthenticateRequest accepts the current model-provider authentication headers. Bearer is used by OpenAI-compatible clients; Anthropic-compatible clients use X-Api-Key. Any other Authorization scheme is rejected rather than being ambiguously combined with X-Api-Key.

func (*Service) Issue

func (service *Service) Issue(ctx context.Context, principalType PrincipalType, subjectID string) (IssuedToken, error)

func (*Service) Revoke

func (service *Service) Revoke(ctx context.Context, keyID string) error

Jump to

Keyboard shortcuts

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