Google Calendar Setup¶
To use Night Routine Scheduler, you need to set up OAuth 2.0 credentials in Google Cloud Console and configure the Google Calendar API.
Prerequisites¶
- A Google account
- Access to Google Cloud Console
- A Google Calendar (can be your primary calendar or a dedicated one)
Step-by-Step Setup¶
1. Create a Google Cloud Project¶
- Go to the Google Cloud Console
- Click on the project dropdown at the top of the page
- Click "New Project"
- Enter a project name (e.g., "Night Routine Scheduler")
- Click "Create"
- Wait for the project to be created, then select it from the project dropdown
2. Enable the Google Calendar API¶
- In the Google Cloud Console, go to APIs & Services → Library
- Search for "Google Calendar API"
- Click on "Google Calendar API" in the results
- Click the "Enable" button
- Wait for the API to be enabled
3. Configure OAuth Consent Screen¶
- Go to APIs & Services → OAuth consent screen
- Select External user type (or Internal if you have a Google Workspace account)
-
Click "Create"
-
Fill in the App Information:
- App name:
Night Routine Scheduler(or your preferred name) - User support email: Your email address
- App logo: (Optional) Upload a logo
- Application home page: (Optional) Your website
- Authorized domains: (Leave empty for local development)
- Developer contact information: Your email address
- App name:
-
Click "Save and Continue"
-
Add Scopes:
- Click "Add or Remove Scopes"
- Filter for "Google Calendar API"
- Select the following scopes:
https://www.googleapis.com/auth/calendar(See, edit, share, and permanently delete all calendars)https://www.googleapis.com/auth/calendar.events(View and edit events on all your calendars)
- Click "Update"
- Click "Save and Continue"
-
Add Test Users (for External apps in testing):
- Click "Add Users"
- Add your email address and any other users who will test the app
- Click "Add"
- Click "Save and Continue"
-
Review the summary and click "Back to Dashboard"
Publishing Status
For personal use, you can leave the app in "Testing" status. Only test users will be able to authenticate. To use with more than 100 users, you'll need to submit the app for verification.
4. Create OAuth 2.0 Credentials¶
- Go to APIs & Services → Credentials
- Click "Create Credentials" → "OAuth client ID"
- Select Application type: "Web application"
-
Name:
Night Routine Scheduler(or your preferred name) -
Add Authorized Redirect URIs:
For local development:
For production (replace with your actual domain):
Callback URL Format
The callback URL must match:
<app_url>/oauth/callbackWhere
app_urlis the value in yourroutine.tomlconfiguration. -
Click "Create"
-
Save Your Credentials:
- A dialog will appear with your Client ID and Client Secret
- Copy both values - you'll need them for configuration
- You can also download the JSON file for backup
Keep Credentials Secret
Never commit your Client Secret to version control or share it publicly. Treat it like a password.
5. Configure Environment Variables¶
Set the OAuth credentials as environment variables:
export GOOGLE_OAUTH_CLIENT_ID="123456789-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com"
export GOOGLE_OAUTH_CLIENT_SECRET="GOCSPX-your-secret-here"
Or add them to your .env file:
GOOGLE_OAUTH_CLIENT_ID=123456789-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=GOCSPX-your-secret-here
For Docker:
environment:
- GOOGLE_OAUTH_CLIENT_ID=123456789-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com
- GOOGLE_OAUTH_CLIENT_SECRET=GOCSPX-your-secret-here
OAuth Scopes Explained¶
The application requires the following Google Calendar API scopes:
| Scope | Purpose |
|---|---|
calendar |
Full access to calendars - needed to create, update, and delete night routine events |
calendar.events |
Access to calendar events - needed to read and modify event details |
Why Full Access?
The application needs full calendar access to:
- Create all-day events for night routine assignments
- Update events when the schedule changes
- Delete events that are no longer needed
- Set up and manage webhook notifications
- Read event details to detect manual overrides
Testing the Setup¶
1. Start the Application¶
Or with Docker:
2. Access the Web Interface¶
Open your browser to the configured app_url (default: http://localhost:8080)
3. Connect to Google Calendar¶
- Click the "Connect Google Calendar" button
- You'll be redirected to Google's OAuth consent screen
- Select your Google account
- Review the permissions requested
- Click "Continue" (or "Allow")
- You'll be redirected back to the application
Unverified App Warning
If your app is in "Testing" status, you'll see a warning that says "Google hasn't verified this app." Click "Advanced" → "Go to Night Routine Scheduler (unsafe)" to proceed. This is normal for apps in testing mode.
4. Select a Calendar¶
After authentication, you'll be redirected to the calendar selection page where you can choose which Google Calendar to use for night routine events.
Production Deployment¶
Domain Configuration¶
For production deployments with a custom domain:
- Add your domain to Authorized Domains (in OAuth consent screen)
-
Add the production callback URL to Authorized Redirect URIs:
-
Update your configuration to match:
HTTPS Requirements¶
HTTPS Required for Production
Google OAuth requires HTTPS for production deployments. Use a reverse proxy (nginx, Caddy, Traefik) with Let's Encrypt for SSL certificates.
Multiple Environments¶
If you have multiple environments (development, staging, production), create separate OAuth credentials for each:
- Create separate Google Cloud projects for each environment, or
- Create multiple OAuth clients in the same project with different redirect URIs
Example:
| Environment | Redirect URI |
|---|---|
| Development | http://localhost:8080/oauth/callback |
| Staging | https://staging.example.com/oauth/callback |
| Production | https://night-routine.example.com/oauth/callback |
Troubleshooting¶
"Error 400: redirect_uri_mismatch"¶
Cause: The redirect URI in your request doesn't match any of the authorized redirect URIs in Google Cloud Console.
Solution:
- Check your
app_urlinroutine.toml - Verify the callback URL is constructed as
<app_url>/oauth/callback - Ensure this exact URL is added to Authorized Redirect URIs in Google Cloud Console
- Check for typos, trailing slashes, and protocol (http vs https)
"Access Blocked: This app's request is invalid"¶
Cause: OAuth consent screen is not properly configured.
Solution:
- Complete all required fields in the OAuth consent screen
- Ensure scopes are added correctly
- If using "External" type in testing, add your email as a test user
"This app is blocked"¶
Cause: The app is not published and you're not a test user.
Solution:
- Go to OAuth consent screen in Google Cloud Console
- Add your email address to test users
- Or publish the app (requires verification for 100+ users)
"Calendar API has not been used in project"¶
Cause: The Google Calendar API is not enabled for your project.
Solution:
- Go to APIs & Services → Library
- Search for "Google Calendar API"
- Click "Enable"
Credentials Not Working¶
Checklist:
- Calendar API is enabled
- OAuth consent screen is configured
- Credentials are created as "Web application" type
- Redirect URI matches exactly (including protocol and path)
- Environment variables are set correctly
- No extra whitespace in environment variables
- Client Secret hasn't been regenerated (old secret is invalid)
Security Best Practices¶
Protect Your Credentials¶
- Never commit credentials to version control
- Use environment variables or secret management systems
- Rotate Client Secret if it's ever exposed
- Use different credentials for development and production
Limit Scope Access¶
- Only request the scopes you need
- Review granted permissions regularly
- Revoke unused OAuth tokens
Monitor Usage¶
- Check Google Cloud Console for unusual API usage
- Set up billing alerts
- Enable audit logs
Restrict Access¶
- Use "Internal" user type if you have Google Workspace
- Limit test users to trusted accounts
- Regularly review who has access to the app
Managing OAuth Tokens¶
OAuth tokens are stored in the SQLite database and automatically refreshed when needed.
Viewing Token Status¶
The application shows authentication status on the home page.
Revoking Access¶
To revoke access:
- Go to your Google Account Permissions
- Find "Night Routine Scheduler"
- Click "Remove Access"
- Restart the application and re-authenticate
Token Refresh¶
Access tokens expire after 1 hour but are automatically refreshed using the stored refresh token. You don't need to do anything.
API Quotas and Limits¶
Google Calendar API has the following default limits:
- Queries per day: 1,000,000
- Queries per 100 seconds per user: 10,000
Night Routine Scheduler is well within these limits for normal use:
- Initial setup: ~5-10 API calls
- Daily sync: ~2-5 API calls
- Webhook notifications: 1 API call per calendar change
Monitoring Usage
You can monitor your API usage in Google Cloud Console under APIs & Services → Dashboard