auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.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 holds the dashboard-auth domain: the single dashboard user, their WebAuthn credentials, in-flight ceremonies, and sessions. See openspec/changes/add-pipeline-dashboard/specs/dashboard-auth/spec.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserExists       = errors.New("a user account already exists")
	ErrNoUser           = errors.New("no user account has been registered yet")
	ErrCeremonyNotFound = errors.New("ceremony not found or expired")
	ErrSessionNotFound  = errors.New("session not found or expired")
)

Sentinel errors, so a caller can errors.Is against a specific condition instead of matching on message text.

Functions

This section is empty.

Types

type Service

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

Service orchestrates the WebAuthn registration and login ceremonies: begin, persist the in-flight ceremony state, finish, and issue a session.

func NewService

func NewService(webAuthn *webauthn.WebAuthn, store Store) *Service

NewService returns a Service.

func (*Service) BeginLogin

BeginLogin starts the login ceremony. Returns ErrNoUser if no dashboard account has been registered yet.

func (*Service) BeginRegistration

func (s *Service) BeginRegistration(ctx context.Context) (*protocol.CredentialCreation, string, error)

BeginRegistration starts the registration ceremony. Returns ErrUserExists if the single dashboard account already exists.

func (*Service) FinishLogin

func (s *Service) FinishLogin(ctx context.Context, ceremonyID string, r *http.Request) (string, error)

FinishLogin completes the login ceremony started by BeginLogin, returning a new session id on success.

func (*Service) FinishRegistration

func (s *Service) FinishRegistration(ctx context.Context, ceremonyID string, r *http.Request) (User, string, error)

FinishRegistration completes the registration ceremony started by BeginRegistration, creating the dashboard user, storing their credential, and establishing a session (the OpenAPI contract's "account created, session established" -- registration logs the new account straight in, the same as a login would).

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, sessionID string) error

Logout ends a session.

type Store

type Store interface {
	// CreateUser creates the single dashboard user with the given WebAuthn
	// user handle (generated once, at the start of the registration
	// ceremony, and threaded through to here so the stored handle matches
	// the one the ceremony ran against). Returns ErrUserExists if a user
	// already exists.
	CreateUser(ctx context.Context, userHandle []byte, displayName string) (User, error)
	// GetUser returns the single dashboard user, or ErrNoUser if none has
	// registered yet.
	GetUser(ctx context.Context) (User, error)

	// PutCredential creates or updates (e.g. after a login's sign-count
	// bump) a credential belonging to userID.
	PutCredential(ctx context.Context, userID string, cred webauthn.Credential) error
	// CredentialsForUser returns every credential belonging to userID.
	CredentialsForUser(ctx context.Context, userID string) ([]webauthn.Credential, error)

	// SaveCeremony stores the SessionData for an in-flight WebAuthn
	// ceremony, keyed by an opaque id the caller generates.
	SaveCeremony(ctx context.Context, id string, data []byte, expiresAt time.Time) error
	// TakeCeremony reads and deletes a ceremony's data -- a ceremony is
	// single-use. Returns ErrCeremonyNotFound if it doesn't exist or has
	// expired.
	TakeCeremony(ctx context.Context, id string) ([]byte, error)

	// CreateSession creates a new session for userID, returning its opaque id.
	CreateSession(ctx context.Context, userID string) (string, error)
	// Session returns the userID a session id belongs to. Returns
	// ErrSessionNotFound if it doesn't exist or has expired.
	Session(ctx context.Context, sessionID string) (string, error)
	// DeleteSession ends a session.
	DeleteSession(ctx context.Context, sessionID string) error
}

Store is the port the domain persists users, credentials, in-flight ceremonies, and sessions through.

type User

type User struct {
	ID          string
	UserHandle  []byte
	DisplayName string
	CreatedAt   time.Time
}

User is the dashboard's single account.

Directories

Path Synopsis
Package sqlite is the SQLite-backed adapter for the auth.Store port.
Package sqlite is the SQLite-backed adapter for the auth.Store port.

Jump to

Keyboard shortcuts

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