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 ¶
- Variables
- type Service
- func (s *Service) BeginLogin(ctx context.Context) (*protocol.CredentialAssertion, string, error)
- func (s *Service) BeginRegistration(ctx context.Context) (*protocol.CredentialCreation, string, error)
- func (s *Service) FinishLogin(ctx context.Context, ceremonyID string, r *http.Request) (string, error)
- func (s *Service) FinishRegistration(ctx context.Context, ceremonyID string, r *http.Request) (User, string, error)
- func (s *Service) Logout(ctx context.Context, sessionID string) error
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
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 ¶
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).
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.