A FastAPI server that handles OAuth 2.0 authentication with Google APIs for TaskIQ. This server can be deployed to Vercel or any other serverless platform.
- Google OAuth 2.0 authentication flow
- Token storage and management
- API endpoints for authentication and token status
- Easy deployment to Vercel
-
Ensure you have the required dependencies:
pip install -r requirements.txt
-
Make sure you have a
.gauth.jsonfile with your Google OAuth credentials in the project directory. -
Update the
.envfile with your configuration:CLIENT_SECRETS_FILE=".gauth.json" REDIRECT_URI="https://taskiq.io/auth/google" TOKEN_STORAGE_DIR="./tokens"
To run the server locally:
uvicorn app:app --reload --host 0.0.0.0 --port 8000or simply:
python app.pyThe server will be available at http://localhost:8000.
GET /: Check if the server is runningGET /generate-auth-url?email={email}: Generate an OAuth URL for a userGET /auth/google: OAuth callback endpoint (redirect URI)GET /token/{user_id}: Check if a user has a valid token
-
Install the Vercel CLI:
npm install -g vercel
-
Log in to Vercel:
vercel login
-
Deploy the project:
vercel
-
For production deployment:
vercel --prod
-
Update Google Cloud Console settings:
- Add your production domain (e.g.,
https://taskiq.io/auth/google) to the authorized redirect URIs in the Google Cloud Console.
- Add your production domain (e.g.,
-
For production, consider:
- Using a more secure token storage solution
- Adding authentication to protect the API endpoints
- Implementing proper error handling and logging
To use this auth server with the TaskIQ Telegram bot:
- Update the bot to use the auth server URL for generating authentication links
- Update the relevant handlers to check token status via the
/token/{user_id}endpoint - Use the saved tokens to authenticate API requests to Google services