passkey

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 9 Imported by: ? 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 passkey manages WebAuthn passkey registration and authentication.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAttemptBlocked   = errors.New("passkey attempt blocked")
	ErrConflict         = errors.New("passkey conflict")
	ErrInactiveCeremony = errors.New("passkey ceremony is inactive")
	ErrInvalidCeremony  = errors.New("invalid or expired passkey ceremony")
	ErrInvalidConfig    = errors.New("invalid passkey configuration")
	ErrInvalidInput     = errors.New("invalid passkey input")
	ErrInvalidRecord    = errors.New("invalid passkey record")
	ErrLastCredential   = errors.New("cannot remove the last sign-in method")
	ErrNotFound         = errors.New("passkey record not found")
	ErrVerification     = errors.New("passkey verification failed")
)

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Operation Operation
	SubjectID string
	SourceKey string
}

type AttemptGuard

type AttemptGuard interface {
	Check(ctx context.Context, attempt Attempt) error
}

type Authentication

type Authentication struct {
	SubjectID    string
	CloneWarning bool
}

type AuthenticationStarted

type AuthenticationStarted struct {
	Token     string
	Options   *protocol.CredentialAssertion
	ExpiresAt time.Time
}

type Ceremony

type Ceremony struct {
	Type      CeremonyType
	TokenHash CeremonyHash
	SubjectID string
	Session   webauthnlibrary.SessionData
	CreatedAt time.Time
	ExpiresAt time.Time
}

type CeremonyHash

type CeremonyHash token.Hash

type CeremonyType

type CeremonyType string
const (
	CeremonyRegistration   CeremonyType = "registration"
	CeremonyAuthentication CeremonyType = "authentication"
)

type CompleteInput

type CompleteInput struct {
	CeremonyToken string
	SubjectID     string
	Response      []byte
	SourceKey     string
}

type Config

type Config struct {
	RelyingPartyID   string
	RelyingPartyName string
	Origins          []string
	CeremonyLifetime time.Duration
	AttemptGuard     AttemptGuard
	SecurityEvents   SecurityEventSink
	Now              func() time.Time
}

type Credential

type Credential = webauthnlibrary.Credential

type EventType

type EventType string
const (
	EventRegistered           EventType = "passkey_registered"
	EventRegistrationFailed   EventType = "passkey_registration_failed"
	EventAuthenticated        EventType = "passkey_authenticated"
	EventAuthenticationFailed EventType = "passkey_authentication_failed"
	EventCloneWarning         EventType = "passkey_clone_warning"
	EventRemoved              EventType = "passkey_removed"
)

type Manager

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

func NewManager

func NewManager(store Store, config Config) (*Manager, error)

func (*Manager) BeginAuthentication

func (manager *Manager) BeginAuthentication(ctx context.Context) (AuthenticationStarted, error)

func (*Manager) BeginRegistration

func (manager *Manager) BeginRegistration(
	ctx context.Context,
	subjectID string,
) (RegistrationStarted, error)

func (*Manager) CompleteAuthentication

func (manager *Manager) CompleteAuthentication(
	ctx context.Context,
	input CompleteInput,
) (Authentication, error)

func (*Manager) CompleteRegistration

func (manager *Manager) CompleteRegistration(
	ctx context.Context,
	input CompleteInput,
) (Credential, error)

func (*Manager) List

func (manager *Manager) List(ctx context.Context, subjectID string) ([]Credential, error)

func (*Manager) Remove

func (manager *Manager) Remove(
	ctx context.Context,
	subjectID string,
	credentialID []byte,
	sourceKey string,
) error

type Operation

type Operation string
const (
	OperationRegister     Operation = "register"
	OperationAuthenticate Operation = "authenticate"
)

type RegistrationStarted

type RegistrationStarted struct {
	Token     string
	Options   *protocol.CredentialCreation
	ExpiresAt time.Time
}

type SecurityEvent

type SecurityEvent struct {
	Type       EventType
	SubjectID  string
	SourceKey  string
	OccurredAt time.Time
}

type SecurityEventSink

type SecurityEventSink interface {
	Record(ctx context.Context, event SecurityEvent)
}

type Store

type Store interface {
	FindUserBySubject(ctx context.Context, subjectID string) (User, error)
	FindUserByCredential(ctx context.Context, credentialID, userHandle []byte) (User, error)
	CreateCeremony(ctx context.Context, ceremony Ceremony) error
	FindCeremony(ctx context.Context, ceremonyHash CeremonyHash) (Ceremony, error)
	CompleteRegistration(
		ctx context.Context,
		ceremonyHash CeremonyHash,
		subjectID string,
		credential Credential,
		completedAt time.Time,
	) error
	CompleteAuthentication(
		ctx context.Context,
		ceremonyHash CeremonyHash,
		subjectID string,
		previous Credential,
		updated Credential,
		completedAt time.Time,
	) error
	DeleteCredential(ctx context.Context, subjectID string, credentialID []byte, deletedAt time.Time) error
}

Store keeps complete credential records, consumes ceremonies with credential writes, and preserves another sign-in method when deleting a credential.

type User

type User struct {
	SubjectID   string
	Handle      []byte
	Name        string
	DisplayName string
	Credentials []Credential
}

func (User) WebAuthnCredentials

func (user User) WebAuthnCredentials() []Credential

func (User) WebAuthnDisplayName

func (user User) WebAuthnDisplayName() string

func (User) WebAuthnID

func (user User) WebAuthnID() []byte

func (User) WebAuthnName

func (user User) WebAuthnName() string

Jump to

Keyboard shortcuts

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