Using Google OAuth2 for local development requires setting up credentials in the Google Cloud Console, configuring a redirect URI for localhost
, and using the Google APIs client library to handle authentication.
1. Create a Google Cloud Project & Enable APIs
- Go to Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to APIs & Services → Library.
- Enable the Google Calendar API (or any other API you need).
2. Create OAuth 2.0 Client Credentials
- Go to APIs & Services → Credentials.
- Click Create Credentials → OAuth Client ID.
- Select Web Application as the application type.
- Add authorized redirect URIs:
- For local dev:
http://localhost:3000/oauth2callback
(or the port you're using).
- Save and download the
credentials.json
.
3. Install Google Auth Library
npm install googleapis google-auth-library
4. Implement Local OAuth Flow
Here’s a Node.js example for local dev: