OAuth & Integrations
Google Ads
- Backend callback route:
GET/POST /api/google-ads/auth/callbackhandled bygoogleAdsController.handleAuthCallback - Frontend success page:
frontend/app/oauth/google-ads/success/page.tsx - Available accounts:
GET /api/google-ads/auth/available-accounts?accessToken=... - Create account:
POST /api/google-ads/accounts/create
Redirect URIs (production)
- If using custom domains:
- Google Ads:
https://app.ostenai.com/api/google-ads/callback(ensure this maps to backend.../auth/callbackor adjust accordingly) - Meta Ads:
https://app.ostenai.com/api/meta-ads/callback - TikTok Ads:
https://app.ostenai.com/api/tiktok-ads/callback
- Google Ads:
- Backend Cloud Run example env:
GOOGLE_OAUTH_REDIRECT_URI=https://<cloudrun-host>/api/google-ads/auth/callback
Known Requirements / Gotchas
- Google Ads API requires:
Authorization: Bearer <OAUTH2_ACCESS_TOKEN>Content-Type: application/json
- API access belongs to the Google Cloud project that owns the OAuth client (
GOOGLE_OAUTH_CLIENT_ID). Google sunset developer tokens on 2026-09-09; the client sendsdeveloper-tokenonly whenGOOGLE_ADS_DEVELOPER_TOKENis set, and the API ignores it. A future major version will reject the header, so remove the token before that upgrade. See https://developers.google.com/google-ads/api/docs/api-policy/developer-token customers:listAccessibleCustomersmay return 501 if the Cloud project's API access level does not allow the operation or the account hierarchy is not a Manager account (MCC).- The service handles 501 by returning guidance/demo entries; upgrade access or use test manager + test accounts.
Meta Ads & TikTok Ads
- Similar available-accounts and connect flows under
/api/meta-ads/*and/api/tiktok-ads/* - Frontend success pages under
frontend/app/oauth/meta-ads/success/page.tsxandfrontend/app/oauth/tiktok-ads/success/page.tsx - Meta upgrades the short-lived code straight to a long-lived (~60 day) token,
and that token cannot be refreshed server-side — after it expires the user
has to re-authorize. The sync records
marketing_accounts.sync_status = 'needs_reconnect'when it hits Graph code 190, andGET /api/meta-ads/connection-statusreports both that and tokens expiring within 7 days. The internaldocs/meta-ads.mdcovers the connector in full.
Google Analytics 4 (GA4)
- GA4 uses a frontend callback page to complete the OAuth flow and let the user pick a property.
- Frontend callback route:
frontend/app/(dashboard)/dashboard/google-analytics/callback/page.tsx
Redirect URI (production)
- Google Analytics (GA4):
https://app.ostenai.com/dashboard/google-analytics/callback- Set this exact URI in the Google Cloud Console OAuth client.
- Set backend env var
GOOGLE_ANALYTICS_REDIRECT_URIto the same URI so backend-generated links remain consistent.
Notes
- GA scripts must only load on public pages (landing, marketing, login, signup, data deletion) — do not load on OAuth success pages or any dashboard pages.
- After callback, the frontend exchanges the authorization code with the backend to list properties and save the selected property.