feat(auth): implement auth layer - identity resolution #28

Merged
addison merged 4 commits from exe-dev-bot/kiosk:feat/auth-layer into main 2026-02-21 08:01:01 -05:00
Contributor

Implements the Auth Layer section of spec 002 (22 tasks). Adds auth.go with API key validation, root login, OTP claim, and bearer token extraction. All functions are testable independently of HTTP.

Implements the Auth Layer section of spec 002 (22 tasks). Adds `auth.go` with API key validation, root login, OTP claim, and bearer token extraction. All functions are testable independently of HTTP.
Add auth.go with:
- AuthUser type for resolved identity
- GenerateAPIKey: 32 random bytes, base64url, bcrypt hash
- ValidateAPIKey: iterate keys, bcrypt compare, check revoked/expired,
  update last_used_at. Sentinel errors: ErrInvalidKey, ErrRevokedKey,
  ErrExpiredKey
- ExtractBearerToken: parse Bearer token from Authorization header
- LoginRoot: validate root credentials, generate 24h key, enforce max 3
  concurrent keys (revoke oldest on overflow)
- ClaimOTP: validate OTP via bcrypt scan, burn code, create non-expiring
  key in atomic transaction. Sentinel errors: ErrInvalidOTP, ErrExpiredOTP,
  ErrClaimedOTP

Co-authored-by: Shelley <shelley@exe.dev>
Cover all spec tasks:
- API key validation (valid, revoked, missing, malformed, expired,
  non-expired, null expires_at, last_used_at update)
- Bearer token extraction (valid, missing, malformed)
- Root login (correct creds, wrong password, non-existent user,
  max 3 keys revoke oldest)
- OTP claim (valid code burns OTP, expired, already claimed,
  non-existent, atomic concurrent claims)

Co-authored-by: Shelley <shelley@exe.dev>
Co-authored-by: Shelley <shelley@exe.dev>
fix(auth): remove lint suppression and unused goroutine parameter
All checks were successful
CI / ci (pull_request) Successful in 58s
cf6f660bf7
Co-authored-by: Shelley <shelley@exe.dev>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kwila/kiosk!28
No description provided.