Google Cloud OAuth app setup
This guide is for DevOps / platform operators who configure Fiko's backend before agents can click "Connect with Google" in the dashboard. Follow every numbered step in order.
Before you start
You need:
Google account with access to Google Cloud Console
Use a company account, not a personal Gmail that only you control.
Fiko messaging-service public URL
Production: https://msg.fikosrv.com
Access to edit .env on fiko-messaging-service and fiko-core-service
Both services need the same OAuth client ID/secret and encryption key.
Gmail ingest: polling vs Pub/Sub
Fiko supports two ways to detect new Gmail mail. Both work — Pub/Sub is faster for production.
| Mode | Env required | Latency | When to use |
|---|---|---|---|
| Polling (default) | OAuth only — no GMAIL_PUBSUB_TOPIC | ~1 minute | Fallback if Pub/Sub not configured yet |
| Pub/Sub push (real-time) | GMAIL_PUBSUB_TOPIC + push subscription per channel | Seconds | Production — recommended |
Step-by-step setup
Part A — Create project and enable APIs
- 1Open console.cloud.google.com and sign in.
- 2Top bar → click the project dropdown → New Project.
- Project name: Fiko Email (or your product name)
- Click Create and wait until the project is ready
- Select the new project from the top bar dropdown
- 3Left menu → APIs & Services → Library.
- 4Search Gmail API → open it → click Enable.
- 5Back to Library → search Cloud Pub/Sub API → Enable.
Expected result
Both Gmail API and Cloud Pub/Sub API should show status Enabled. Pub/Sub is required for real-time push in Part G — enable it now so you do not need to return later.
Part B — OAuth consent screen
- 6Left menu → APIs & Services → OAuth consent screen.
- 7Choose User type:
- External — for any Gmail / Google Workspace customer (most cases)
- Internal — only if every mailbox is in your single Workspace org
- 8Fill App information → click Save and Continue:
Field Example value Notes App name Fiko Shown on Google consent screen User support email [email protected] Must be a Google account you control App logo (optional) Not required for Testing Application home page https://fiko.com Your product URL Application privacy policy link https://fiko.com/privacy Required before Production publish Application terms of service link https://fiko.com/terms Required before Production publish Authorized domains fiko.com, fikosrv.com Domains used in links above Developer contact information [email protected] Google may email about verification - 9On Scopes → click Add or Remove Scopes → filter "Gmail" → add both scopes below (full URLs):Fiko authorize URL also sets
OAuth scopes Fiko requests
Scope URL (exact) Purpose in Fiko https://www.googleapis.com/auth/gmail.modify Read inbox, mark read/unread, move messages — ingest + threading https://www.googleapis.com/auth/gmail.send Send replies from Fiko on behalf of the connected mailbox access_type=offlineandprompt=consentso refresh tokens are issued reliably. Then Update → Save and Continue. - 10On Test users (while app is in Testing) → Add users → enter every support mailbox email that will connect during pilot (e.g. [email protected]).
Expected result
In Testing mode, only listed test users can complete OAuth. Refresh tokens may expire after ~7 days until you publish to Production — see CASA ops guide. - 11Click Back to Dashboard. Publishing status should show Testing.
App information
Publishing status
- .../auth/gmail.modify
- .../auth/gmail.send
Part C — Create OAuth client (Web)
- 12Left menu → APIs & Services → Credentials.
- 13Click Create Credentials → OAuth client ID.
- 14Application type: Web application. Name: Fiko Gmail.
- 15Under Authorized redirect URIs → Add URI → paste exactly:
https://msg.fikosrv.com/v2/email/oauth/google/callback
Expected result
The URI must matchGOOGLE_OAUTH_CALLBACK_URLcharacter-for-character (including http vs https, no trailing slash). - 16Click Create. A popup shows Client ID and Client secret. Copy both immediately — you cannot view the secret again later.
Application type
https://msg.fikosrv.com/v2/email/oauth/google/callback
Client ID
Client secret
Part D — Generate encryption key and set env vars
- 17Generate
EMAIL_ENCRYPTION_KEY(32 random bytes, base64). Run once and reuse the same value on both services:node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"Expected result
Store in secrets manager. If this key changes, existing stored OAuth refresh tokens cannot be decrypted — agents must reconnect mailboxes. - 18On fiko-messaging-service, set:
GOOGLE_OAUTH_CLIENT_ID=123456789-xxxx.apps.googleusercontent.com GOOGLE_OAUTH_CLIENT_SECRET=GOCSPX-xxxxxxxx GOOGLE_OAUTH_CALLBACK_URL=https://msg.fikosrv.com/v2/email/oauth/google/callback EMAIL_ENCRYPTION_KEY=your-base64-32-byte-key GMAIL_PUBSUB_TOPIC=projects/YOUR_GCP_PROJECT/topics/gmail-push
- GMAIL_PUBSUB_TOPIC: set after Part G topic is created, or leave unset for polling-only mode
- GOOGLE_OAUTH_CALLBACK_URL must match Google Console redirect URI exactly
- 19On fiko-core-service, copy client ID, secret, and encryption key (callback URL not required on core):
GOOGLE_OAUTH_CLIENT_ID=... GOOGLE_OAUTH_CLIENT_SECRET=... EMAIL_ENCRYPTION_KEY=...
- 20Redeploy / restart both services after updating env.
Part E — Verify OAuth
- 21In Fiko dashboard → Apps → Email → Add new → Connect mailbox → Connect Google.
- 22After Allow, browser redirects back to Fiko. Finish setup → connected mailbox shown.
Expected result
If you see redirect_uri_mismatch, fix URI in Google Console vsGOOGLE_OAUTH_CALLBACK_URL. - 23Send test email → open Chats → reply from Fiko.
Part G — Gmail Pub/Sub push (production, recommended)
Production flow: Gmail users.watch (labelIds: INBOX) → Google Pub/Sub topic → POST /v2/email/gmail/push/:channelId → immediate sync. Cron at 2 AM renews watch (Gmail watch expires in ≤7 days).
- 24Pub/Sub → Topics → Create topic → ID:
gmail-push. - 25Topic → Permissions → Grant access → principal
[email protected]→ role Pub/Sub Publisher → Save.Expected result
Without this permission, Gmailusers.watchfails silently or logs permission errors. - 26Set env on messaging-service and redeploy:
GMAIL_PUBSUB_TOPIC=projects/YOUR_GCP_PROJECT/topics/gmail-push
- 27Connect (or reconnect) Gmail channel in Fiko — after OAuth attach, Fiko calls Gmail
users.watchwith the topic above.Expected result
messaging-service log: Gmail Pub/Sub watch enabled for channel ... - 28Get channel ID from Fiko (Apps → Email → Channel Details → Provider channel ID or URL).
- 29Pub/Sub → Subscriptions → Create subscription — fill every field:
Push subscription fields
Field Value Notes Subscription ID gmail-push-{channelId} One subscription per Gmail channel Select a Cloud Pub/Sub topic gmail-push Topic from step 24 Delivery type Push Not Pull Endpoint URL https://msg.fikosrv.com/v2/email/gmail/push/{channelId} Replace {channelId} with real UUID Enable authentication Unchecked Fiko endpoint is public HTTPS; OIDC optional later Enable payload unwrapping Checked Delivers Gmail notification JSON directly Acknowledgement deadline 10 seconds (default) Increase only if Fiko sync is slow Message retention duration 7 days (default) Retry policy Retry immediately (default) Dead-letter topic (none) Optional for ops monitoring Expected result
Each new Gmail channel needs a new push subscription because the endpoint path includes:channelId. - 30Send test email → chat should appear within seconds.
Fiko endpoints (Google)
| Endpoint | Method | Purpose |
|---|---|---|
| https://msg.fikosrv.com/v2/email/oauth/google/callback | GET / POST | OAuth redirect after user clicks Allow |
| https://msg.fikosrv.com/v2/email/gmail/push/{channelId} | POST | Pub/Sub push when new mail arrives |
Environment variables reference
| Variable | Service | Example |
|---|---|---|
| GOOGLE_OAUTH_CLIENT_ID | messaging + core | xxx.apps.googleusercontent.com |
| GOOGLE_OAUTH_CLIENT_SECRET | messaging + core | GOCSPX-... |
| GOOGLE_OAUTH_CALLBACK_URL | messaging only | .../v2/email/oauth/google/callback |
| EMAIL_ENCRYPTION_KEY | messaging + core | Base64 32-byte key (same value both services) |
| GMAIL_PUBSUB_TOPIC | messaging only | projects/.../topics/gmail-push — bật Pub/Sub push (Part G) |
Troubleshooting
Error 400: redirect_uri_mismatch
Google Console redirect URI ≠ GOOGLE_OAUTH_CALLBACK_URL. Open Credentials → your OAuth client → fix URI → save → retry OAuth.
Access blocked: app has not completed verification
User is not on Test users list, or app needs Production publish. Add email under OAuth consent → Test users.
Mail arrives slowly (minutes instead of seconds)
Check Part G — push subscription endpoint must match channelId and GMAIL_PUBSUB_TOPIC must be set before connect/reconnect.
Pub/Sub push not reaching Fiko
Verify push subscription endpoint URL, HTTPS is publicly reachable, and [email protected] has Pub/Sub Publisher on the topic.
Test configuration fails in Fiko
Core-service missing GOOGLE_OAUTH_* or EMAIL_ENCRYPTION_KEY. Both must match messaging-service.
Never commit Client Secret or EMAIL_ENCRYPTION_KEY to git. Use secrets manager in production.