- Google Cloud Console account
- Flask app running on
http://localhost:5000
- Go to Google Cloud Console
- Select your project (or create one if needed)
- Navigate to APIs & Services → Credentials
- Click on your OAuth 2.0 Client ID (or create one if you haven't)
- Under Authorized redirect URIs, add:
http://localhost:5000/auth/gmail/callback - Click Save
Add these to your .env file:
# OAuth Configuration
OAUTH_REDIRECT_URI=http://localhost:5000/auth/gmail/callback
SECRET_KEY=your-secret-key-here-minimum-32-chars
# Agent Settings (optional)
AGENT_POLL_INTERVAL=60 # seconds between email checksGenerate a secure SECRET_KEY:
import secrets
print(secrets.token_hex(32))-
Start Flask Dashboard:
python wsgi.py
-
Open Browser: Navigate to
http://localhost:5000 -
Authenticate:
- Dashboard will show "Gmail Authentication Required"
- Click "Connect Gmail" button
- Authorize the app in Google OAuth consent screen
- You'll be redirected back to dashboard
- Agent will auto-start
- User clicks "Connect Gmail" button
- Redirected to Google OAuth consent screen
- User authorizes the app
- Google redirects to
/auth/gmail/callbackwith code - App exchanges code for credentials
- Credentials saved to
token.json - Session created with user email
- Agent automatically starts in background
- Dashboard displays with agent status
If you restart Flask and token.json still valid:
- Agent automatically resumes on startup
- No need to re-authenticate
- Dashboard shows authenticated state
Dashboard shows:
- ✅ Running (green pulsing dot) - Agent is active
- ⭕ Stopped (gray dot) - Agent is not running
- Uptime - How long agent has been running
- Last Poll - When agent last checked for emails
- Processed - Number of emails processed
- Make sure you added
http://localhost:5000/auth/gmail/callbackto Google Cloud Console - Check for typos in OAUTH_REDIRECT_URI in .env
- Check Flask logs for errors
- Verify token.json exists and is valid
- Restart Flask app
- Sessions last 30 days by default
- Can be changed in
app/__init__.py→PERMANENT_SESSION_LIFETIME
For production (e.g., Heroku, AWS):
-
Update OAUTH_REDIRECT_URI:
OAUTH_REDIRECT_URI=https://yourdomain.com/auth/gmail/callback
-
Add production URL to Google Cloud Console authorized redirect URIs
-
Use strong SECRET_KEY (never commit to git)
-
Consider using Redis for session storage instead of filesystem