Gmail OAuth Setup
Set up Gmail API access via gog CLI with manual OAuth flow. Use when setting up Gmail integration, renewing expired OAuth tokens, or troubleshooting Gmail authentication on headles…
kai-jar
@kai-jar
What This Skill Does
Walks through the complete OAuth 2.0 setup for Gmail API access using the gog CLI, including Google Cloud project creation, credential configuration, and headless server authentication.
Replaces manually navigating Google Cloud Console and writing custom OAuth scripts by providing a repeatable, headless-friendly authentication flow.
When to Use It
- Set up Gmail API access for a new gog CLI installation
- Renew expired OAuth tokens on a headless server
- Troubleshoot Gmail authentication errors like 'invalid_grant' or 'redirect_uri_mismatch'
- Publish an OAuth app in Google Cloud Console to get permanent refresh tokens
- Configure file-based keyring for storing Gmail credentials on a remote machine
Install
$ openclaw skills install @kai-jar/gmail-oauthGmail OAuth Setup
Headless-friendly OAuth flow for Gmail API access using gog CLI.
Prerequisites
gogCLI installed (brew install steipete/tap/gogcli)- Google Cloud project with OAuth credentials (Desktop app type)
- Gmail API enabled in the project
Quick Setup
1. Create Google Cloud Project & Credentials
- Go to https://console.cloud.google.com
- Create a new project (or select existing)
- Enable Gmail API: APIs & Services → Library → search "Gmail API" → Enable
- Configure OAuth consent screen: APIs & Services → OAuth consent screen
- Choose "External" user type
- Fill in app name, user support email
- Add scopes:
gmail.modify(or others as needed) - Important: Click "PUBLISH APP" for permanent tokens (see Troubleshooting)
- Create credentials: APIs & Services → Credentials → Create Credentials → OAuth client ID
- Application type: Desktop app
- Download the JSON file
2. Configure gog
gog auth credentials /path/to/client_secret.json
gog auth keyring file # Use file-based keyring for headless
export GOG_KEYRING_PASSWORD="your-password" # Add to .bashrc
3. Run Auth Flow
Run scripts/gmail-auth.sh interactively, or:
# Generate URL
scripts/gmail-auth.sh --url
# User opens URL, approves, copies code from localhost redirect
# Exchange code (do this quickly - codes expire in minutes!)
scripts/gmail-auth.sh --exchange CODE EMAIL
4. Verify
gog gmail search 'is:unread' --max 5 --account you@gmail.com
Troubleshooting
"Access blocked: [app] has not completed the Google verification process"
Cause: App is in "Testing" mode and the Gmail account isn't a test user.
Solutions (choose one):
-
Publish the app (recommended):
- Google Cloud Console → APIs & Services → OAuth consent screen
- Click "PUBLISH APP" → Confirm
- No Google review needed for personal use
- Tokens become permanent
-
Add test user:
- OAuth consent screen → Test users → + ADD USERS
- Add the Gmail address you're authorizing
- Tokens still expire in 7 days
"Google hasn't verified this app" warning screen
This is normal for personal apps. Click:
- Advanced (bottom left)
- Go to [app name] (unsafe)
Safe to proceed since you own the app.
Token expires in 7 days
Cause: App is in "Testing" mode.
Fix: Publish the app (see above). Published apps get permanent refresh tokens.
"invalid_request" or "invalid_grant" errors
Causes:
- Authorization code expired (they only last a few minutes)
- Code was already used
- Redirect URI mismatch
Fix: Generate a fresh auth URL and complete the flow quickly. Paste the code immediately after getting it.
"redirect_uri_mismatch" error
Cause: The redirect URI in the token exchange doesn't match what was used in the auth URL.
Fix: This script uses http://localhost. Make sure both the auth URL and exchange use the same redirect URI.
Page hangs after approving permissions (mobile)
Cause: Browser trying to connect to localhost which doesn't exist on phone.
Fix:
- Use a desktop browser instead
- Or tap the address bar while it's "hanging" - the URL contains the code
- The URL will look like:
http://localhost/?code=4/0ABC...
Multiple permission checkboxes causing hangs
Cause: Too many OAuth scopes requested.
Fix: Use minimal scopes. gmail.modify alone is usually sufficient and shows just one permission.
Can't find project in Google Cloud Console
Cause: Signed into wrong Google account.
Fix: Check which account owns the project:
- Click profile icon (top right)
- Switch accounts
- Check project dropdown for each account
"invalid_request" with oob redirect (new projects)
Cause: Google deprecated urn:ietf:wg:oauth:2.0:oob for OAuth clients created after 2022.
Fix: Use http://localhost redirect instead (this script's default). After approval, browser redirects to localhost with code in URL.
Scopes Reference
| Scope | Access |
|---|---|
gmail.modify | Read, send, delete, manage labels (recommended) |
gmail.readonly | Read only |
gmail.send | Send only |
gmail.compose | Create drafts, send |
Files
scripts/gmail-auth.sh— Interactive auth helper
Tips
- Publish your app — Avoids test user limits and 7-day token expiry
- Exchange codes quickly — They expire in minutes
- Use desktop browser — Mobile browsers can be finicky with localhost redirects
- One scope is enough —
gmail.modifycovers most use cases
Top skills in this category
Google Meet
@hith3shGoogle Meet API integration with managed OAuth. Create meeting spaces, inspect conference records, retrieve recordings and transcripts, and manage meeting pa...
API Gateway
@byungkyuCall third-party APIs through the Maton gateway, which injects the credential for an app the user has already connected. Use this skill when the user names a connected app and a concrete action in it - read a mailbox, query a CRM, file an issue, update a spreadsheet, etc.
gmail
@byungkyuGmail API integration with managed OAuth. Read, send, and manage emails, threads, labels, and drafts. Use this skill when users want to interact with Gmail. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Calls run through the `maton` CLI with OAuth login, or over raw HTTP with a Maton API key where the CLI cannot be installed. Every call is authenticated as the user's connection and reaches only what that connection's authorization allows, which the provider enforces on every request; the endpoints documented here are the ones this skill uses, and any other endpoint of this app needs the user to ask for it by name. Default to read and list calls, and confirm every write or new connection with the user. This file also documents the three constructs that turn a Gmail connection into automation, in the order they are used: the connection (the first step), a hosted function that runs a Gmail action through the Maton SDK, and a trigger that calls that function on a schedule or on an event. Those sections are the platform's own reference text, shared with the api-gateway skill, with Gmail examples; they add no Gmail capability - Gmail is itself an event source, so its own events are in `references/google-mail/triggers.md`, and the files under `references/<source>/triggers.md` are the platform's event catalogues for the sources Maton offers (time, Calendly, GitHub, Gmail, HubSpot, Linear, Notion, Slack, Stripe).
1password
@steipeteSet up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
WhatsApp Business
@byungkyuWhatsApp Business API integration with managed OAuth. Send messages, manage templates, and handle conversations. Use this skill when users want to interact with WhatsApp Business. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Calls run through the `maton` CLI with OAuth login, or over raw HTTP with a Maton API key where the CLI cannot be installed. Every call is authenticated as the user's connection and reaches only what that connection's authorization allows, which the provider enforces on every request; the endpoints documented here are the ones this skill uses, and any other endpoint of this app needs the user to ask for it by name. Default to read and list calls, and confirm every write or new connection with the user. This file also documents the three constructs that turn a WhatsApp Business connection into automation, in the order they are used: the connection (the first step), a hosted function that runs a WhatsApp Business action through the Maton SDK, and a trigger that calls that function on a schedule or on an event. Those sections are the platform's own reference text, shared with the api-gateway skill, with WhatsApp Business examples; they add no WhatsApp Business capability - WhatsApp Business is not an event source, a trigger cannot read WhatsApp Business data, and the files under `references/<source>/triggers.md` are the platform's event catalogues for the sources Maton offers (time, Calendly, GitHub, Gmail, HubSpot, Linear, Notion, Slack, Stripe).