challenge

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a ceremony challenge does not exist.
	ErrNotFound = errors.New("challenge: session not found")

	// ErrExpired is returned when a ceremony challenge has expired.
	ErrExpired = errors.New("challenge: session expired")

	// ErrAlreadyConsumed is returned when a ceremony challenge has already been used.
	ErrAlreadyConsumed = errors.New("challenge: session already consumed")
)

Functions

This section is empty.

Types

type CeremonyType

type CeremonyType string

CeremonyType classifies the WebAuthn ceremony being performed.

const (
	// CeremonyRegistration indicates an in-flight registration ceremony.
	CeremonyRegistration CeremonyType = "registration"

	// CeremonyAuthentication indicates an in-flight authentication ceremony.
	CeremonyAuthentication CeremonyType = "authentication"
)

type MemoryOption

type MemoryOption func(*MemoryStore)

MemoryOption customizes MemoryStore.

func WithClock

func WithClock(clock func() time.Time) MemoryOption

WithClock sets a custom clock function for testing.

type MemoryStore

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

MemoryStore provides a thread-safe in-memory implementation of challenge.Store.

func NewMemoryStore

func NewMemoryStore(opts ...MemoryOption) *MemoryStore

NewMemoryStore constructs a new in-memory challenge store.

func (*MemoryStore) Consume

func (ms *MemoryStore) Consume(ctx context.Context, id string) (*Session, error)

Consume atomically marks the session as used and returns it.

func (*MemoryStore) Delete

func (ms *MemoryStore) Delete(ctx context.Context, id string) error

Delete removes a ceremony session.

func (*MemoryStore) DeleteExpired

func (ms *MemoryStore) DeleteExpired(ctx context.Context, before time.Time) (int, error)

DeleteExpired purges expired sessions.

func (*MemoryStore) Get

func (ms *MemoryStore) Get(ctx context.Context, id string) (*Session, error)

Get retrieves a ceremony session without consuming it.

func (*MemoryStore) Save

func (ms *MemoryStore) Save(ctx context.Context, s *Session) error

Save stores a new ceremony session.

type Session

type Session struct {
	// ID is the unique random session token issued to the client.
	ID string `json:"id"`

	// Type distinguishes registration from authentication.
	Type CeremonyType `json:"type"`

	// UserID is the user ID if known during initiation (empty for discoverable authentication).
	UserID string `json:"user_id,omitempty"`

	// FriendlyName holds the device name provided at initiation time.
	FriendlyName string `json:"friendly_name,omitempty"`

	// Data holds the underlying WebAuthn session data (challenge bytes, timeouts, flags).
	Data webauthn.SessionData `json:"data"`

	// CreatedAt marks when the challenge was generated.
	CreatedAt time.Time `json:"created_at"`

	// ExpiresAt marks when the challenge becomes invalid.
	ExpiresAt time.Time `json:"expires_at"`

	// ConsumedAt marks when the challenge was redeemed (nil if still unconsumed).
	ConsumedAt *time.Time `json:"consumed_at,omitempty"`
}

Session holds the transient state of an active WebAuthn ceremony.

func (*Session) Consumed

func (s *Session) Consumed() bool

Consumed reports whether the session has already been consumed.

func (*Session) Expired

func (s *Session) Expired(now time.Time) bool

Expired reports whether the session has expired.

type Store

type Store interface {
	// Save persists a newly generated ceremony session.
	Save(ctx context.Context, s *Session) error

	// Get retrieves a ceremony session without consuming it.
	Get(ctx context.Context, id string) (*Session, error)

	// Consume atomically marks the session as used and returns it.
	// Must return ErrAlreadyConsumed on replay and ErrExpired if expired.
	Consume(ctx context.Context, id string) (*Session, error)

	// Delete removes a ceremony session.
	Delete(ctx context.Context, id string) error

	// DeleteExpired purges sessions that expired before the specified cutoff.
	DeleteExpired(ctx context.Context, before time.Time) (int, error)
}

Store is the persistence contract for transient WebAuthn ceremony sessions.

Jump to

Keyboard shortcuts

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