PluginMind uses a dual-stage authentication flow that keeps tokens server-side while giving the backend full control over sessions.
🧭 Overview
- NextAuth (frontend) handles Google OAuth using the App Router runtime.
- The custom proxy at
src/app/api/proxy/[...path]/route.tsextracts the Google ID token and forwards it to the backend exactly once. - FastAPI validates the token via Google, creates a signed
pm_sessioncookie, and returns it to the browser. - All subsequent requests rely on the
pm_sessioncookie—no access tokens are exposed to client-side code.
Rendering diagram…
🛠️ Backend Endpoints
| Endpoint | Method | Description |
|---|---|---|
/auth/google | POST | Validates Google ID token and issues pm_session. Requires body { "id_token": "..." }. |
/auth/logout | POST | Clears the session cookie using get_logout_cookie_settings(). |
/auth/validate | GET | Legacy helper returning { valid: true } for valid bearer tokens. |
/auth/me | GET | Returns the authenticated user using the session cookie (structured for the Next.js frontend). |
All endpoints pull the session via get_session_user or get_session_payload (app/middleware/session_auth.py).
🍪 Session Cookie Details
Loading code snippet…
Good to know
- Sessions last 24 hours by default.
- Set
SESSION_COOKIE_DOMAINto share cookies across subdomains. BACKEND_SESSION_SECRETmust be at least 32 characters.
🧾 Request Examples
Bind (one-time)
Loading code snippet…
Authenticated API call
Loading code snippet…
🧪 Testing & Mocks
- Backend tests use
create_session_tokento set cookies directly (tests/test_generic_processing.py). - JWT unit tests mock Google verification so they do not hit the network (
tests/test_jwt_security.py). - CI runs
TESTING=1 pytest, which automatically provisions safe dummy environment variables (tests/conftest.py).
🧱 Hardening Tips
- Always call backend APIs with
credentials: 'include'in fetch/axios. - Rotate
BACKEND_SESSION_SECRETif you suspect token leakage. - Configure
NEXT_PUBLIC_SECURE_TOKENS=trueto prevent NextAuth from exposing provider tokens in the browser. - For local development over HTTP, leave
secure=False; for production, setENVIRONMENT=productionso cookies ride HTTPS only.
Stay safe and session-based! 🛡️