62 lines
3.3 KiB
Markdown
62 lines
3.3 KiB
Markdown
# Passkey Authentication Implementation Plan
|
|
|
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
|
|
**Goal:** Replace repeated Basic Auth prompts on `dzen.nstarikov.ru` with Face ID, Touch ID, Windows Hello, or another WebAuthn passkey while retaining a guarded emergency Basic Auth path.
|
|
|
|
**Architecture:** FastAPI will own authentication for `/admin` and `/api`: public WebAuthn challenge endpoints issue registration and authentication options, verification creates an HttpOnly session cookie, and a middleware protects all other admin/API routes. SQLite stores passkey credentials and sessions. Caddy will stop applying Basic Auth to the main host; the existing Basic Auth configuration remains available on a separate emergency host until passkey login is verified.
|
|
|
|
**Tech Stack:** FastAPI, SQLAlchemy/SQLite, `webauthn` Python package, browser WebAuthn API, React/Vite, Caddy.
|
|
|
|
---
|
|
|
|
### Task 1: Persist passkeys and sessions
|
|
|
|
**Files:**
|
|
- Modify: `requirements.txt`
|
|
- Modify: `app/models.py`
|
|
- Modify: `app/database.py`
|
|
- Modify: `app/config.py`
|
|
|
|
- [ ] Add `webauthn==3.0.0`, passkey credential/session models, and migration columns/tables.
|
|
- [ ] Add RP ID, RP name, session lifetime, and one-time bootstrap settings.
|
|
- [ ] Verify imports and SQLite table creation in the container.
|
|
|
|
### Task 2: Add FastAPI WebAuthn flows and protection
|
|
|
|
**Files:**
|
|
- Create: `app/auth.py`
|
|
- Modify: `app/main.py`
|
|
- Modify: `app/routes.py`
|
|
|
|
- [ ] Add registration options/verification and authentication options/verification using `generate_*_options`, `verify_*_response`, and JSON helpers from `webauthn`.
|
|
- [ ] Set and clear Secure, HttpOnly, SameSite=Lax session cookies.
|
|
- [ ] Permit only auth bootstrap/challenge/verify/health without a session; require a session for `/admin`, `/api`, and logs WebSockets.
|
|
- [ ] Keep first-device registration guarded by the existing Basic Auth during migration.
|
|
|
|
### Task 3: Add passkey UI
|
|
|
|
**Files:**
|
|
- Modify: `admin/src/App.tsx`
|
|
- Modify: `admin/src/index.css`
|
|
|
|
- [ ] Show a compact login screen when the API returns `401`.
|
|
- [ ] Add «Войти по Face ID / Touch ID» and «Зарегистрировать это устройство» actions using `navigator.credentials`.
|
|
- [ ] Add logout and clear error states; preserve the existing dashboard after session restoration.
|
|
- [ ] Keep the UI usable in standalone iPhone PWA and desktop browsers.
|
|
|
|
### Task 4: Update Caddy and verify migration
|
|
|
|
**Files:**
|
|
- Modify: `Caddyfile.server`
|
|
- Modify: `Caddyfile.snippet` if needed
|
|
|
|
- [ ] Remove Basic Auth from the main `dzen.nstarikov.ru` route while keeping an emergency host/path protected by Basic Auth.
|
|
- [ ] Validate Caddy configuration, deploy API/admin/Caddy changes, and verify HTTPS origin and cookie behavior.
|
|
- [ ] Test registration and login on iPhone Safari/PWA and a desktop platform authenticator.
|
|
|
|
### Task 5: Regression checks
|
|
|
|
- [ ] Run `python3 -m py_compile app/*.py` and `npm --prefix admin run build`.
|
|
- [ ] Verify unauthenticated API returns `401`, authenticated API returns `200`, `/feed` remains public, and WebSocket logs accept the session cookie.
|
|
- [ ] Verify the emergency Basic Auth path remains reachable before removing any old credential mechanism.
|