2.5 KiB
2.5 KiB
Google Vein
OAuth2-based connector for Google APIs (Sheets, Drive).
Status: DEVELOPMENT
Setup
-
Create Google Cloud project and OAuth2 credentials:
- Go to https://console.cloud.google.com/apis/credentials
- Create OAuth 2.0 Client ID (Web application)
- Add authorized redirect URI:
https://artery.mcrn.ar/google/oauth/callback - Enable Google Sheets API and Google Drive API
-
Copy
.env.exampleto.envand fill in credentials:cp .env.example .env # Edit .env with your credentials -
Install dependencies:
pip install -r requirements.txt -
Run standalone:
python run.py
OAuth Flow
Unlike Jira/Slack (simple token auth), Google uses OAuth2:
- Start: Visit
/google/oauth/start- redirects to Google login - Callback: Google redirects to
/google/oauth/callbackwith code - Exchange: Code exchanged for access_token + refresh_token
- Storage: Tokens saved to
storage/tokens_{user_id}.json - Use: Subsequent requests use stored tokens
- Refresh: Expired tokens auto-refreshed using refresh_token
Endpoints
Authentication
GET /google/health- Check auth statusGET /google/oauth/start- Start OAuth flowGET /google/oauth/callback- OAuth callback (called by Google)GET /google/oauth/logout- Clear stored tokens
Google Sheets
GET /google/spreadsheets/{id}- Get spreadsheet metadataGET /google/spreadsheets/{id}/sheets- List all sheetsGET /google/spreadsheets/{id}/values?range=Sheet1!A1:D10- Get cell values
All endpoints support ?text=true for LLM-friendly text output.
Architecture
core/ # Isolated - can run without FastAPI
├── oauth.py # Google OAuth2 client
├── sheets.py # Google Sheets API client
└── config.py # Settings
api/ # FastAPI wrapper
└── routes.py # Endpoints
models/ # Data models
├── spreadsheet.py # Pydantic models
└── formatter.py # Text output
storage/ # Token persistence (gitignored)
Token Storage
For development/demo: File-based storage in storage/
For production: Override TokenStorage in vein/oauth.py:
- Redis for scalability
- Database for audit trail
- Per-user tokens when integrated with auth system
Future APIs
- Google Drive (file listing, download)
- Gmail (read messages)
- Calendar (events)
Each API gets its own client in core/ (e.g., core/drive.py).