Overview
The SFLUV API uses Privy JWT tokens for authentication. Privy provides wallet-based authentication, and all API requests must include a valid JWT token in theAccess-Token header.
Authentication Flow
The authentication process follows these steps:- User authenticates with Privy (wallet connection)
- Frontend obtains JWT access token from Privy
- Frontend includes token in API requests via
Access-Tokenheader - Backend middleware validates token and extracts user DID
- Request proceeds with authenticated user context
Getting a JWT Token
Frontend Implementation
Using the Privy React SDK:AppProvider Pattern
The SFLUV frontend uses a centralizedauthFetch helper:
JWT Token Structure
Privy JWT tokens are signed using ES256 (ECDSA with P-256 and SHA-256) and contain these claims:Standard Claims
| Claim | Description | Example |
|---|---|---|
iss | Issuer - Must be “privy.io” | "privy.io" |
aud | Audience - Your Privy App ID | "clpqr-abc-def-123" |
sub | Subject - User’s DID | "did:privy:clwxyz123" |
exp | Expiration timestamp | 1709654400 |
iat | Issued at timestamp | 1709568000 |
Token Example
Backend Validation
The backend validates JWT tokens using middleware.Middleware Flow
From/backend/utils/middleware/auth.go:14:
Validation Steps
From/backend/utils/middleware/auth.go:43:
Signature Verification
From/backend/utils/middleware/auth.go:73:
Making Authenticated Requests
Basic GET Request
POST Request with Body
Role-Protected Endpoint
Admin Authentication
Admin endpoints support two authentication methods:1. JWT with Admin Role
Standard JWT authentication where the user hasis_admin = true.
2. Admin Key Header
For scripted/automated access, use theX-Admin-Key header:
/backend/router/router.go:218:
User Context
After successful authentication, the middleware injectsuserDid into the request context. This is available to all handlers:
Authentication Errors
Missing Token
Invalid Token
Expired Token
Insufficient Permissions
Environment Configuration
Required environment variables for authentication:Security Best Practices
Token Storage
Token Storage
- Never store JWT tokens in localStorage (XSS vulnerable)
- Privy SDK handles token storage securely
- Tokens are short-lived and automatically refreshed
Token Transmission
Token Transmission
- Always use HTTPS in production
- Include tokens only in headers, never in URLs
- Use the
Access-Tokenheader, notAuthorization
Admin Keys
Admin Keys
- Store
ADMIN_KEYsecurely (never in frontend) - Rotate admin keys periodically
- Use admin keys only for automated scripts
Token Validation
Token Validation
- Backend validates issuer (
iss), audience (aud), and expiration (exp) - Signature verified using Privy’s public key
- Algorithm restricted to ES256 only
Testing Authentication
To test authentication locally:-
Start the backend:
-
Run the frontend:
-
Connect wallet and get token:
-
Test API call:
Next Steps
API Overview
Learn about base URLs, response formats, and errors
User Endpoints
Explore user management endpoints