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 CredentialInfo
- type Service
- func (s *Service) AuthenticateToken(ctx context.Context, rawToken string) (string, error)
- func (s *Service) BeginAddCredential(ctx context.Context) (*protocol.CredentialCreation, string, error)
- 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) FinishAddCredential(ctx context.Context, ceremonyID, label string, r *http.Request) 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) IssueToken(ctx context.Context, userID string) (Token, string, error)
- func (s *Service) ListCredentials(ctx context.Context, userID string) ([]CredentialInfo, error)
- func (s *Service) Logout(ctx context.Context, sessionID string) error
- func (s *Service) RevokeCredential(ctx context.Context, userID string, credentialID []byte) error
- func (s *Service) RevokeToken(ctx context.Context, userID, tokenID string) error
- type Store
- type Token
- 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") 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
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 ¶
NewService returns a Service.
func (*Service) AuthenticateToken ¶ added in v0.30.0
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
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
ListCredentials returns userID's registered credentials' listing metadata (label, creation date), oldest first.
func (*Service) RevokeCredential ¶ added in v0.33.0
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.
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.