Documentation
¶
Overview ¶
Package auth provides WebAuthn-based authentication with passkey registration, login, session management, and invite-based user onboarding. Store interfaces allow pluggable persistence backends.
Index ¶
- Variables
- func CreateBootstrapInvite(ctx context.Context, invites InviteStore, email string, duration time.Duration) (string, error)
- func GenerateToken() (plaintext, hash string, err error)
- func HashToken(token string) string
- func PrintBootstrapURL(baseURL, token string)
- type Config
- type Invite
- type InviteStore
- type PasskeyStore
- type Server
- type Session
- type SessionStore
- type User
- type UserStore
- type WebAuthnWrapper
- func (w *WebAuthnWrapper) BeginLogin(user *User, credentials []webauthn.Credential) (*protocol.CredentialAssertion, *webauthn.SessionData, error)
- func (w *WebAuthnWrapper) BeginRegistration(user *User) (*protocol.CredentialCreation, *webauthn.SessionData, error)
- func (w *WebAuthnWrapper) FinishLogin(user *User, sessionData webauthn.SessionData, ...) (*webauthn.Credential, error)
- func (w *WebAuthnWrapper) FinishRegistration(user *User, sessionData webauthn.SessionData, ...) (*webauthn.Credential, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = axon.ErrNotFound ErrDuplicateUsername = errors.New("username already taken") )
View Source
var StaticFiles embed.FS
Functions ¶
func CreateBootstrapInvite ¶
func CreateBootstrapInvite(ctx context.Context, invites InviteStore, email string, duration time.Duration) (string, error)
CreateBootstrapInvite creates an admin bootstrap invite for the given email. It returns the plaintext token for use in a registration URL.
func GenerateToken ¶
GenerateToken creates a cryptographically random token and returns both the plaintext (for cookies) and the SHA-256 hash (for storage).
func PrintBootstrapURL ¶
func PrintBootstrapURL(baseURL, token string)
PrintBootstrapURL prints the registration URL for a bootstrap invite.
Types ¶
type InviteStore ¶
type InviteStore interface {
CreateInvite(ctx context.Context, email, tokenHash string, expiresAt time.Time, isBootstrap bool) (*Invite, error)
ValidateInviteByHash(ctx context.Context, tokenHash string) (*Invite, error)
MarkInviteUsedByHash(ctx context.Context, tokenHash string) error
CleanExpiredInvites(ctx context.Context) error
}
type PasskeyStore ¶
type PasskeyStore interface {
SavePasskey(ctx context.Context, userID string, credential *webauthn.Credential, deviceName string) error
GetUserPasskeys(ctx context.Context, userID string) ([]webauthn.Credential, error)
UpdateSignCount(ctx context.Context, credentialID []byte, signCount uint32) error
DeletePasskey(ctx context.Context, credentialID []byte) error
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(cfg Config, users UserStore, sessions SessionStore, passkeys PasskeyStore, invites InviteStore, staticFiles *embed.FS) (*Server, error)
type SessionStore ¶
type SessionStore interface {
CreateSession(ctx context.Context, userID, tokenHash string, expiresAt time.Time) (*Session, error)
ValidateSessionByHash(ctx context.Context, tokenHash string) (*Session, error)
DeleteSessionByHash(ctx context.Context, tokenHash string) error
DeleteUserSessions(ctx context.Context, userID string) error
CleanExpiredSessions(ctx context.Context) error
}
type UserStore ¶
type UserStore interface {
CreateUser(ctx context.Context, username, email, displayName string, isAdmin bool) (*User, error)
GetUserByEmail(ctx context.Context, email string) (*User, error)
GetUserByUsername(ctx context.Context, username string) (*User, error)
GetUserByID(ctx context.Context, id string) (*User, error)
ListUsers(ctx context.Context) ([]*User, error)
DeleteUser(ctx context.Context, id string) error
SetAdmin(ctx context.Context, id string, isAdmin bool) error
}
type WebAuthnWrapper ¶
type WebAuthnWrapper struct {
// contains filtered or unexported fields
}
func NewWebAuthnWrapper ¶
func NewWebAuthnWrapper(rpID, rpName string, rpOrigins []string) (*WebAuthnWrapper, error)
func (*WebAuthnWrapper) BeginLogin ¶
func (w *WebAuthnWrapper) BeginLogin(user *User, credentials []webauthn.Credential) (*protocol.CredentialAssertion, *webauthn.SessionData, error)
func (*WebAuthnWrapper) BeginRegistration ¶
func (w *WebAuthnWrapper) BeginRegistration(user *User) (*protocol.CredentialCreation, *webauthn.SessionData, error)
func (*WebAuthnWrapper) FinishLogin ¶
func (w *WebAuthnWrapper) FinishLogin(user *User, sessionData webauthn.SessionData, response *protocol.ParsedCredentialAssertionData, credentials []webauthn.Credential) (*webauthn.Credential, error)
func (*WebAuthnWrapper) FinishRegistration ¶
func (w *WebAuthnWrapper) FinishRegistration(user *User, sessionData webauthn.SessionData, response *protocol.ParsedCredentialCreationData) (*webauthn.Credential, error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.