This is the Python FastAPI backend for authenticating AI Builders community members using Circle's Headless API.
- ✅ Circle Headless API integration
- ✅ Email/password login (Circle membership verification)
- ✅ Google OAuth login
- ✅ JWT token generation and validation
- ✅ User session management
- ✅ Protected API endpoints
- Python 3.8 or higher
- Circle Business plan or higher
- Circle community: community.theaibuilders.dev
cd backend
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCopy .env.example to .env:
cp .env.example .envEdit .env and fill in your credentials:
# Circle API
CIRCLE_HEADLESS_TOKEN=your_headless_auth_token_here
CIRCLE_COMMUNITY_ID=your_community_id
CIRCLE_API_URL=https://app.circle.so/api/v1
# Google OAuth
GOOGLE_CLIENT_ID=695004012662-a3981egieh12pqcbb57sbiug99b48mos.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-Z57roRadsZ74hWhr0U-Jl3TP_OG
# Your App
JWT_SECRET=your_super_secret_jwt_key_change_this
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=10080
# CORS
FRONTEND_URL=http://localhost:4321- Go to Circle admin → Settings → Developers → Tokens
- Click "Create API Token"
- Select "Headless Auth"
- Name it: "Custom Web App Auth"
- Copy and add to
.env
python main.pyOr using uvicorn directly:
uvicorn main:app --reload --host 0.0.0.0 --port 8000The API will be available at:
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4For production deployment, you need to:
-
Set the
ENV_FILEenvironment variable to.env.prod:export ENV_FILE=.env.prod -
Or set environment variables directly in your deployment platform:
FRONTEND_URL=https://tutorial.theaibuilders.devCIRCLE_HEADLESS_TOKEN=your_tokenCIRCLE_COMMUNITY_ID=your_idGOOGLE_CLIENT_ID=your_client_idGOOGLE_CLIENT_SECRET=your_secretJWT_SECRET=your_secret_key
-
Ensure CORS is properly configured - The backend automatically includes both:
- The
FRONTEND_URLfrom environment variables https://tutorial.theaibuilders.devas a hardcoded fallback
- The
-
Start the server:
ENV_FILE=.env.prod uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
Login with email and password (verifies Circle membership)
Request:
{
"email": "user@example.com",
"password": "password123"
}Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer"
}Login with Google OAuth
Request:
{
"credential": "google_oauth_credential_token"
}Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer"
}Get current authenticated user (requires Bearer token)
Headers:
Authorization: Bearer <your_jwt_token>
Response:
{
"id": 12345,
"email": "user@example.com",
"name": "John Doe",
"avatar_url": "https://..."
}Refresh Circle access token
Request:
{
"refresh_token": "circle_refresh_token"
}Response:
{
"access_token": "new_circle_token",
"refresh_token": "new_refresh_token",
"expires_in": 3600
}backend/
├── main.py # FastAPI application entry point
├── config.py # Configuration and environment variables
├── models.py # Pydantic models
├── requirements.txt # Python dependencies
├── .env # Environment variables (not in git)
├── .env.example # Environment variables template
├── services/
│ ├── circle_service.py # Circle API integration
│ └── auth_service.py # JWT and Google OAuth
├── routers/
│ └── auth.py # Authentication endpoints
└── middleware/
└── auth_middleware.py # Token verification middleware
- Never commit
.env- It contains sensitive credentials - Change JWT_SECRET - Use a strong, unique secret key
- HTTPS in production - Always use HTTPS in production
- Token expiration - Tokens expire after 7 days by default
- CORS configuration - Update FRONTEND_URL for your domain
curl http://localhost:8000/healthcurl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'curl http://localhost:8000/auth/me \
-H "Authorization: Bearer <your_token>"Make sure you're in the backend directory and virtual environment is activated:
cd backend
source venv/bin/activate
pip install -r requirements.txtCheck that FRONTEND_URL in .env matches your frontend URL.
- Verify your Circle API token is valid
- Ensure you have Headless Auth permissions
- Check that the community ID is correct
MIT