auth

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 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")
	ErrTokenNotFound      = errors.New("token not found, expired, or revoked")
	ErrCredentialNotFound = errors.New("credential not found")
	ErrLastCredential     = errors.New("cannot revoke the account's last remaining credential")
)

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 CredentialInfo added in v0.33.0

type CredentialInfo struct {
	ID        []byte
	Label     string
	CreatedAt time.Time
	// Revocable is false only for the account's last remaining credential,
	// the one RevokeCredential refuses (ErrLastCredential).
	Revocable bool
}

CredentialInfo is a WebAuthn credential's metadata for the credential- management UI -- never the credential itself (public key, sign count, ...), which stays internal to the WebAuthn ceremony. ID is the raw credential id; the HTTP layer is what encodes it for the wire (see support-multiple-passkeys/design.md's "base64url of the credential ID" decision).

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) AuthenticateToken added in v0.30.0

func (s *Service) AuthenticateToken(ctx context.Context, rawToken string) (string, error)

AuthenticateToken returns the userID a raw API token belongs to. Returns ErrTokenNotFound if the token doesn't exist, has expired, or has been revoked.

func (*Service) BeginAddCredential added in v0.33.0

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

BeginAddCredential starts an authenticated "add another passkey" ceremony for the account's existing user, excluding credentials already registered to it -- standard WebAuthn behavior for "register another", and the reason this loads the real user via userWithCredentials rather than constructing a tempUser the way the anonymous BeginRegistration does (support-multiple-passkeys/design.md's "reuse BeginRegistration/ FinishRegistration against the real user" decision).

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) FinishAddCredential added in v0.33.0

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

FinishAddCredential completes the ceremony started by BeginAddCredential, storing the new credential under a user-supplied label.

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) IssueToken added in v0.30.0

func (s *Service) IssueToken(ctx context.Context, userID string) (Token, string, error)

IssueToken creates a new API token for userID, returning its metadata and its raw secret -- the only time the raw secret is ever available.

func (*Service) ListCredentials added in v0.33.0

func (s *Service) ListCredentials(ctx context.Context, userID string) ([]CredentialInfo, error)

ListCredentials returns userID's registered credentials' listing metadata (label, creation date), oldest first.

func (*Service) Logout

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

Logout ends a session.

func (*Service) RevokeCredential added in v0.33.0

func (s *Service) RevokeCredential(ctx context.Context, userID string, credentialID []byte) error

RevokeCredential revokes a credential belonging to userID. Returns ErrCredentialNotFound if no such credential exists for that user, or ErrLastCredential if it's the account's only remaining credential.

func (*Service) RevokeToken added in v0.30.0

func (s *Service) RevokeToken(ctx context.Context, userID, tokenID string) error

RevokeToken revokes tokenID, scoped to userID. Returns ErrTokenNotFound if no such token exists for that user.

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
	// PutCredentialLabeled creates a new credential belonging to userID
	// with a user-supplied label -- the authenticated "add a passkey"
	// path, as opposed to PutCredential's anonymous-registration and
	// sign-count-bump uses, neither of which have a label to set.
	PutCredentialLabeled(ctx context.Context, userID string, cred webauthn.Credential, label string) error
	// CredentialsForUser returns every credential belonging to userID.
	CredentialsForUser(ctx context.Context, userID string) ([]webauthn.Credential, error)
	// CredentialInfosForUser returns every credential belonging to userID
	// as its listing metadata (label, creation date), for the credential-
	// management UI.
	CredentialInfosForUser(ctx context.Context, userID string) ([]CredentialInfo, error)
	// RevokeCredential deletes a credential belonging to userID, scoped by
	// its raw id. Returns ErrCredentialNotFound if no such credential
	// exists for that user, or ErrLastCredential if it's the account's
	// only remaining credential -- both checked and applied in a single
	// transaction, so a concurrent revoke of the account's last two
	// credentials can't zero it out (support-multiple-passkeys/design.md's
	// "Concurrent revoke" risk).
	RevokeCredential(ctx context.Context, userID string, credentialID []byte) 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

	// CreateToken creates a new API token for userID, returning its
	// metadata and its raw secret -- the only time the raw secret is ever
	// available.
	CreateToken(ctx context.Context, userID string) (Token, string, error)
	// TokenUserID returns the userID a raw token belongs to. Returns
	// ErrTokenNotFound if the token doesn't exist, has expired, or has
	// been revoked.
	TokenUserID(ctx context.Context, rawToken string) (string, error)
	// RevokeToken revokes a token by id, scoped to userID. Returns
	// ErrTokenNotFound if no such token exists for that user.
	RevokeToken(ctx context.Context, userID, tokenID string) error
}

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

type Token added in v0.30.0

type Token struct {
	ID        string
	UserID    string
	CreatedAt time.Time
	ExpiresAt time.Time
}

Token is an API token's metadata -- never its raw secret, which is only ever available at creation. See add-api-token-auth/design.md's "Hash the token at rest" decision.

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