Overview
Harbor Parking API uses Bearer token authentication with JWT (JSON Web Tokens) issued by Supabase Auth. All API endpoints require authentication except for public documentation.Authentication Flow
1
User Registration
Users sign up through the Harbor Parking web interface with email and apartment details.
2
Email Verification
Users must verify their email address before proceeding.
3
Admin Approval
Building administrators review and approve new users for security.
4
Token Acquisition
Approved users can obtain JWT tokens through login or direct API authentication.
Getting a JWT Token
Method 1: Web Application Login
The easiest way to get a token for testing:- Visit Harbor Parking Login
- Sign up and get admin approval
- Log in and extract the token from:
- Browser Developer Tools → Application → Local Storage
- Network tab during API requests
- Browser console:
localStorage.getItem('supabase.auth.token')
Method 2: Direct API Authentication
Using Your Token
Include the JWT token in theAuthorization header for all API requests:
Token Properties
JWT tokens contain user information and permissions:sub- User ID (UUID)email- User’s email addressexp- Token expiration (Unix timestamp)aud- Audience (“authenticated”)
Token Expiration
JWT tokens expire after 1 hour for security. Handle expiration gracefully:Permission Levels
Different user roles have varying API access:Regular User (Approved)
- ✅ Profile management
- ✅ Own parking spots CRUD
- ✅ Create availabilities for owned spots
- ✅ View all available spots
- ✅ Create and manage own claims
- ❌ Admin endpoints
Building Admin
- ✅ All regular user permissions
- ✅ User approval/rejection
- ✅ Verify parking spot ownership
- ✅ View all claims in building
- ✅ Access admin dashboard
- ❌ Multi-building management
Unapproved User
- ✅ View own profile only
- ❌ All other endpoints return 403
Security Best Practices
Never expose JWT tokens in client-side code, URLs, or logs. Treat them like passwords.
Client-Side Security
- Secure Storage: Use httpOnly cookies or secure storage APIs
- HTTPS Only: Never send tokens over HTTP in production
- Token Rotation: Implement automatic token refresh
- Logout Cleanup: Clear tokens on user logout
- Scope Validation: Check user permissions before UI actions
Server-Side Validation
- Verify Signature: Validate token signature with Supabase public key
- Check Expiration: Reject expired tokens
- Validate Claims: Verify audience, issuer, and custom claims
- Rate Limiting: Implement per-user rate limits
- Audit Logging: Log authentication events
Common Authentication Errors
401 Unauthorized - Missing Token
401 Unauthorized - Missing Token
401 Unauthorized - Invalid Token
401 Unauthorized - Invalid Token
403 Forbidden - Account Not Approved
403 Forbidden - Account Not Approved
Solution: Wait for admin approval
403 Forbidden - Insufficient Permissions
403 Forbidden - Insufficient Permissions
Solution: Check if admin permissions needed
Testing Authentication
Test Tokens
For development, you can create test users:Postman Setup
-
Create Environment Variables:
base_url:https://harbor-parking.vercel.app/apijwt_token: Your JWT token
-
Set Authorization Header:
- Type: Bearer Token
- Token:
{{jwt_token}}
-
Pre-request Script (for auto-refresh):