credentials

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Authorization lifecycle stub (S06), matching credentials/authorization. M39 supplies flow registration and Begin/Cancel. AuthService adds one-time callback tokens: Begin creates a pending session; Complete stores credentials and marks it completed so Resolve can read them; Cancel cancels pending sessions and invokes flow.Cancel. A real browser/SDK integration can supply a callback endpoint while retaining this interface.

Package credentials implements credentials and authorization flows, matching credentials/credentials, credentials-local, and authorization upstream. Resolve reads a branded POSIX variable reference before each LLM request, so environment changes become visible on the next turn. Storage Domain persists records with CAS versions and rejects concurrent write conflicts. Describe exposes only presence and writability, never plaintext. Registered authorization flows support list/begin/cancel; S06 adds the complete stub lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthService

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

AuthService orchestrates begin, callback, and credential resolution.

func NewAuthService

func NewAuthService(auth *AuthorizationService, store *Store) *AuthService

NewAuthService binds the flow registry and credential store.

func (*AuthService) Begin

func (s *AuthService) Begin(ctx context.Context, flowID FlowID) (token string, err error)

Begin starts a flow and returns a one-time callback token. Typical flow: list flows, begin, complete externally, then Complete(token, value).

func (*AuthService) Cancel

func (s *AuthService) Cancel(ctx context.Context, token string) error

Cancel cancels a pending session and calls flow.Cancel.

func (*AuthService) Complete

func (s *AuthService) Complete(ctx context.Context, token string, value string) error

Complete simulates an OAuth callback: store value and mark the session completed. Resolve can then retrieve it using the flow's credential reference.

func (*AuthService) List

func (s *AuthService) List() []AuthSession

List returns all sessions deterministically in lexical ID order.

func (*AuthService) Status

func (s *AuthService) Status(token string) (AuthSession, bool)

Status returns the state of a session.

type AuthSession

type AuthSession struct {
	ID        string              `json:"id"`
	FlowID    FlowID              `json:"flowId"`
	Status    AuthStatus          `json:"status"`
	StartedAt time.Time           `json:"startedAt"`
	CredRef   brand.CredentialRef `json:"credRef,omitempty"` // Credential reference written by the callback.
	HasValue  bool                `json:"hasValue"`
}

AuthSession records an authorization flow session.

type AuthStatus

type AuthStatus string

AuthStatus identifies an authorization session state.

const (
	AuthPending   AuthStatus = "pending"   // Waiting for a callback.
	AuthCompleted AuthStatus = "completed" // Credentials have been stored.
	AuthCancelled AuthStatus = "cancelled" // Canceled.
)

Authorization session states.

type AuthorizationService

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

AuthorizationService registers authorization flows.

func NewAuthorizationService

func NewAuthorizationService() *AuthorizationService

NewAuthorizationService creates an authorization service.

func (*AuthorizationService) Begin

func (a *AuthorizationService) Begin(ctx context.Context, id FlowID) (string, error)

Begin starts the specified authorization flow.

func (*AuthorizationService) Cancel

func (a *AuthorizationService) Cancel(ctx context.Context, id FlowID) error

Cancel cancels the specified authorization flow.

func (*AuthorizationService) List

func (a *AuthorizationService) List() []*Flow

List returns registered authorization flows.

func (*AuthorizationService) Register

func (a *AuthorizationService) Register(f *Flow) error

Register registers an authorization flow.

type CredentialInfo

type CredentialInfo struct {
	Ref      brand.CredentialRef `json:"ref"`
	Writable bool                `json:"writable"`
	HasValue bool                `json:"hasValue"`
}

CredentialInfo describes a credential without plaintext.

type Flow

type Flow struct {
	// ID uniquely identifies the flow.
	ID FlowID
	// Name is human-readable.
	Name string
	// Begin returns a prompt or URL for completing authorization; stubs may use a placeholder.
	Begin func(ctx context.Context) (string, error)
	// Cancel cancels the authorization flow.
	Cancel func(ctx context.Context) error
}

Flow describes an authorization flow, such as OAuth authorization code.

type FlowID

type FlowID = brand.CredentialRef

FlowID is a branded authorization-flow identifier.

type Store

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

Store combines cached credentials with Storage Domain CAS persistence.

func NewMemoryStore

func NewMemoryStore() *Store

NewMemoryStore creates an in-memory store for tests or temporary use.

func NewStore

func NewStore(backend storage.Backend) *Store

NewStore creates a store using backend for CAS persistence.

func (*Store) Describe

func (s *Store) Describe(ctx context.Context) []CredentialInfo

Describe exposes references, writability, and presence, never plaintext.

func (*Store) Resolve

func (s *Store) Resolve(ctx context.Context, ref brand.CredentialRef) (string, bool)

Resolve reads the current credential value once before each LLM request.

func (*Store) Set

func (s *Store) Set(ctx context.Context, ref brand.CredentialRef, value string) error

Set writes a credential using the last loaded CAS version; mismatches fail.

func (*Store) Unset

func (s *Store) Unset(ctx context.Context, ref brand.CredentialRef) error

Unset deletes a credential using CAS.

Jump to

Keyboard shortcuts

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