OAuth apps for self-hosting
Overview
Section titled “Overview”Some features let a workspace member connect an external account with OAuth:
- Ad platforms (Meta, Google Ads, TikTok): import campaign structure and daily spend, and send server-side conversions back. Members connect them in the analytics settings, Ad accounts tab. See Ad accounts.
- Google Calendar: read the busy time of a host so booked slots never overlap their other events, and write every booking into the host’s Google Calendar as an event. Members click Connect Google Calendar on a booking calendar. See Calendars.
The Google Sheets form connection needs no OAuth app: each workspace uses its own Google service account key. See Form connections.
The OAuth apps those flows run through (the “client” registered on each platform) belong to whoever operates the installation:
- Cloud — the operator has created the apps and configured them on every installation it runs. Workspace members only click Connect; you do not need this page.
- Self-hosted — you create your own apps, once per installation (or one app shared by several of your installations), and you are the party the platforms review and verify.
This page is for self-hosters and operators.
How it works
Section titled “How it works”Which app unlocks what
Section titled “Which app unlocks what”| Platform app | Unlocks | Secrets on the core worker | Redirect URI to register |
|---|---|---|---|
| Meta | Spend import, Conversions API | META_APP_ID, META_APP_SECRET |
https://<your dashboard host>/oauth/ads/callback |
| Google Ads | Spend import, click conversions | GOOGLE_ADS_CLIENT_ID, GOOGLE_ADS_CLIENT_SECRET, GOOGLE_ADS_DEVELOPER_TOKEN, optional GOOGLE_ADS_LOGIN_CUSTOMER_ID |
https://<your dashboard host>/oauth/ads/callback |
| TikTok | Spend import, Events API | TIKTOK_APP_ID, TIKTOK_APP_SECRET |
https://<your dashboard host>/oauth/ads/callback |
| Google Calendar | Booking calendars | GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET |
https://<your dashboard host>/oauth/google/callback |
Configuration rules
Section titled “Configuration rules”-
Where the secrets go. All of them go on the core worker. Set them with Wrangler from the
apps/corefolder of your installation, or in the Cloudflare dashboard (the core Worker › Settings › Variables and secrets). Values that are not secret (META_APP_ID,GOOGLE_ADS_CLIENT_ID,TIKTOK_APP_ID,GOOGLE_OAUTH_CLIENT_ID) may also be plain variables in thevarsblock of the core worker configuration.Terminal window cd apps/corewrangler secret put META_APP_SECRET # repeat for each secret -
Optional, one at a time. A platform without credentials simply shows as unavailable: the ad account card says Not configured on this installation., and the Google calendar sync answers Google connections are not available on this installation. Nothing else breaks. You can configure platforms one by one.
-
Development. With
ENVIRONMENT=devevery provider is replaced by a deterministic fake: no apps, no credentials, no network. The connect buttons complete instantly and the dashboard says Development mode: connections use a simulated provider. -
Redirect URIs must match exactly (scheme, host and path). The host is the public origin of your dashboard (
APP_ORIGIN). The ads callback can be overridden withADS_OAUTH_REDIRECT_URI(for examplehttps://app.example.com/oauth/ads/callback); the Google one is fixed at/oauth/google/callback. -
Same origin. The OAuth callback must come back to the same origin that started the flow, because the pending connection is kept in the member’s browser session. If one app serves several installations, register one redirect URI per installation origin on that app.
-
Cloud installations and Google. On installations linked to the managed offering (
LICENSE_KEYset), Google Calendar connections are brokered by the control plane and no Google app is needed. An own app, when configured, always takes precedence.
What is stored, and where
Section titled “What is stored, and where”- Ad platform tokens stay server-side in your installation; the browser never sees them. They are refreshed before they expire.
- Google Calendar grants are encrypted with the installation key (
AUTH_ENCRYPTION_KEY) before being stored in the installation database. - Conversions sent to ad platforms carry personal identifiers only as SHA-256 hashes; plaintext email or phone is never sent. See Outbound conversions.
- Disconnecting an account deletes the stored grant. Platforms also list the app in the user’s account permissions, where access can be revoked; a revoked grant shows the connection as Reconnect needed (ads) or disconnected (Google).
Review timelines
Section titled “Review timelines”Every platform lets you test your app before review, but only with your own accounts or test users. Plan the reviews early:
| Platform | Before review | Review | Typical duration |
|---|---|---|---|
| Meta | Development mode: only people with a role on the app | Advanced Access for ads_read, ads_management, business_management, plus business verification |
A few days to about 2 weeks |
| Google Ads | Consent screen in Testing: up to 100 test users. Developer token at Test account level: only Google Ads test accounts | App verification (sensitive adwords scope) and developer token Basic access |
Several days to a few weeks (verification); a few business days (token) |
| TikTok | Sandbox mode: sandbox ad accounts only | Manual app review | A few business days |
| Google Calendar | Consent screen in Testing: up to 100 test users, “unverified app” warning | App verification (calendar.readonly and calendar.events are sensitive scopes) |
Several days to a few weeks |
Step by step
Section titled “Step by step”Requested scopes: ads_read, ads_management, business_management.
Create the Meta app
Section titled “Create the Meta app”-
Make sure you have a Facebook account and a Business Portfolio. App review later requires business verification of that portfolio.
-
Go to developers.facebook.com › My Apps › Create app. Pick the Business app type and attach your business portfolio.
-
On the app dashboard, add the product Facebook Login for Business. Under its Settings, add to Valid OAuth Redirect URIs:
https://<your dashboard host>/oauth/ads/callback -
Add the product Marketing API.
-
In App settings › Basic, note the App ID and the App secret. Fill in the privacy policy URL, the data deletion instructions URL, the app icon and the category: all are required before the app can go live.
Configure amabledata
Section titled “Configure amabledata”-
Set the secrets on the core worker:
Terminal window cd apps/corewrangler secret put META_APP_IDwrangler secret put META_APP_SECRET -
Redeploy, or save the secrets in the Cloudflare dashboard. The Meta card on the Ad accounts tab becomes available immediately.
Test, then request review
Section titled “Test, then request review”-
While the app is in Development mode, people with a role on the app (App roles › Roles: admins, developers, testers) can complete the OAuth flow against the ad accounts they can access. Connect your own ad account end to end: spend sync, reports and outbound conversions.
-
To test conversions without affecting ad delivery, open the Conversions dialog of the connection (Ad accounts tab) and set a Test event code (optional): events then appear in Events Manager › Test events. Clear it when you are done.
-
To let any Meta user connect, switch the app to Live and request Advanced Access for
ads_read,ads_managementandbusiness_management(App review › Permissions and features). Meta asks for completed business verification, a screen recording of the OAuth flow showing why each permission is needed (connect an ad account, spend appears in reports, a conversion is sent), and working privacy policy and data deletion URLs.
Operational notes:
- User tokens are exchanged for long-lived tokens (about 60 days). When one expires, the connection shows Reconnect needed and the member reconnects; nothing is lost.
- Conversions go to the dataset (pixel) set on each connection with the Conversions button of the Ad accounts tab (or
PATCH /ads/connections/{id}); until it is set, the row warns that server-side conversions cannot be sent. See Server-side conversions. - Spend is read per campaign, ad set and ad; deleted entities are zeroed on reconciliation.
- Platform rate limits are handled with backoff by the outbound queue; failed jobs can be sent again from the outbound conversions log.
Requested scope: https://www.googleapis.com/auth/adwords. Google Ads needs two credentials with separate approval tracks: an OAuth client (who the user grants access to) and a developer token (your quota for the Google Ads API).
Create the OAuth client
Section titled “Create the OAuth client”-
Create a project in the Google Cloud console. You can reuse the Calendar project, but separate projects are recommended (see the Google Calendar tab).
-
APIs & Services › Library: enable the Google Ads API.
-
APIs & Services › OAuth consent screen: user type External; fill in the app name, support email, authorized domain, and links to the privacy policy and terms. Add the scope
https://www.googleapis.com/auth/adwords. -
Credentials › Create credentials › OAuth client ID, type Web application, with the authorized redirect URI:
https://<your dashboard host>/oauth/ads/callback -
Note the Client ID and the Client secret.
While the consent screen is in Testing, only listed test users (up to 100) can connect. Publishing to production with the sensitive adwords scope requires app verification: domain ownership through Search Console, brand review, scope justification and usually a demo video.
Get a developer token
Section titled “Get a developer token”-
Create or use a Google Ads manager account.
-
In the manager account, open Admin › API Center and apply for API access. The token starts at Test account level (works only against Google Ads test accounts).
-
Apply for Basic access (form review, typically a few business days), and later Standard access for higher limits.
Configure amabledata
Section titled “Configure amabledata”-
Set the secrets on the core worker:
Terminal window cd apps/corewrangler secret put GOOGLE_ADS_CLIENT_IDwrangler secret put GOOGLE_ADS_CLIENT_SECRETwrangler secret put GOOGLE_ADS_DEVELOPER_TOKEN# only if customer accounts are reached through your manager account:wrangler secret put GOOGLE_ADS_LOGIN_CUSTOMER_ID -
The first three are required: without any of them the Google Ads card shows as unavailable.
GOOGLE_ADS_LOGIN_CUSTOMER_IDis optional: set it to your manager account id (digits; dashes are stripped) when the accounts members connect are accessed through that manager account. It is sent as thelogin-customer-idheader. -
Redeploy.
Prepare conversions
Section titled “Prepare conversions”Outbound conversions are uploaded as click conversions with gclid, wbraid or gbraid, hashed user identifiers (enhanced conversions) and the order id for deduplication. In the advertiser’s Google Ads account:
- create a conversion action of type Import › Other data sources › API;
- use the conversion action id (the digits in its detail URL), or the full
customers/<cid>/conversionActions/<id>resource name, as the event name in the traffic source’s conversion mapping; - enable enhanced conversions for leads on the action if hashed identifiers should match.
The target account defaults to the connected account; override it with customer_id in the connection metadata. Google Ads conversions wait 6 hours after the click before being sent, so the click can settle.
Operational notes:
- Refresh tokens are used; a revoked grant shows the connection as Reconnect needed.
- With a Test account level token, real accounts return
DEVELOPER_TOKEN_NOT_APPROVED: that is the token level, not a bug. - Spend is read per campaign, ad group and ad; the currency follows the ad account.
Scopes to request on the app: Ad Account Management (read), Reporting, and Events API (measurement).
Create the TikTok app
Section titled “Create the TikTok app”-
Use a TikTok for Business account (the same login as Ads Manager).
-
Open the TikTok for Business developer portal and register as a developer (company details, one-time review).
-
My apps › Create an app: name and description of the use case (ads reporting and conversion upload for a CRM), and the Advertiser redirect URL:
https://<your dashboard host>/oauth/ads/callback -
Select the scopes listed above and submit the app for review. Until approval the app works in sandbox mode only (sandbox ad accounts, no real data).
-
Note the App ID and the Secret from the app detail page.
Configure amabledata
Section titled “Configure amabledata”-
Set the secrets on the core worker:
Terminal window cd apps/corewrangler secret put TIKTOK_APP_IDwrangler secret put TIKTOK_APP_SECRET -
Redeploy. The TikTok card on the Ad accounts tab becomes available.
Conversions (Events API): events go to the pixel code set on each connection with the Conversions button of the Ad accounts tab (or PATCH /ads/connections/{id}, see Server-side conversions), with event_source: web, the ttclid click id when present, and hashed identifiers only. A Test event code set in the same dialog routes events to Events Manager › Test events.
Operational notes:
- Access tokens are long-lived and refreshed server-side; a revoked grant shows Reconnect needed.
- Spend is read per campaign, ad group and ad from the reporting endpoint; the advertiser accounts a member can pick are listed at connect time.
- TikTok enforces per-app request limits; the sync cadence and the outbound queue backoff stay under the default tier.
One Google OAuth client powers the booking calendars. Connecting a calendar asks for https://www.googleapis.com/auth/calendar.readonly and https://www.googleapis.com/auth/calendar.events:
calendar.readonlyreads the host’s busy time (free/busy query), so those slots are not offered on the booking page;calendar.eventswrites every booking as an event of the connected calendar: created on booking, moved on reschedule (or to the new host’s calendar), deleted on cancellation. The invitee is listed as attendee, but Google sends no invitation: confirmations and reminders go out by email from amabledata. Failed writes are retried for about 15 hours, and the last failure is shown on the calendar in the Calendars list (see Calendars).
Bookings also become CRM appointments of the host. See Calendars.
Form exports to Google Sheets do not use this client (see Form connections).
Create the OAuth client
Section titled “Create the OAuth client”-
Create a project in the Google Cloud console.
-
APIs & Services › Library: enable the Google Calendar API.
-
APIs & Services › OAuth consent screen: user type External; app name, support email, authorized domain, privacy policy and terms URLs. Add the scopes:
https://www.googleapis.com/auth/calendar.eventshttps://www.googleapis.com/auth/calendar.readonly -
Credentials › Create credentials › OAuth client ID, type Web application, with the authorized redirect URI:
https://<your dashboard host>/oauth/google/callback -
Note the Client ID and the Client secret.
Configure amabledata
Section titled “Configure amabledata”-
Set the secrets on the core worker:
Terminal window cd apps/corewrangler secret put GOOGLE_OAUTH_CLIENT_IDwrangler secret put GOOGLE_OAUTH_CLIENT_SECRET -
Redeploy. Connect Google Calendar works on booking calendars.
Verification
Section titled “Verification”calendar.readonly and calendar.events are sensitive scopes. While the consent screen is in Testing, only listed test users (up to 100) can connect and Google shows an “unverified app” warning. For public production use, submit the app for verification: domain ownership (Search Console), brand review, a justification per scope and usually a short demo video of each flow (connecting a calendar, a busy slot disappearing from the booking page and a booking appearing in Google Calendar). Expect several days to a few weeks.
One project or two?
Section titled “One project or two?”- Same project as Google Ads: one consent screen and one verification covering
adwordsand calendar. Simpler, but any review issue blocks every Google feature at once. - Separate projects (recommended): independent verification timelines, so calendar bookings do not wait for the ads review. The two clients have different ids and secrets (
GOOGLE_OAUTH_*andGOOGLE_ADS_*), which the configuration keeps apart.
Operational notes:
- Refresh tokens are used; a revoked grant makes the account show as disconnected and the member reconnects from the same settings page.
- Calendars connected with
calendar.readonlyonly keep their busy time, but bookings are not written to them; the Calendars list shows “Bookings are not written to Google Calendar: disconnect and connect Google again to allow it.” under the account. Disconnect and reconnect Google Calendar to grantcalendar.events.
Reference
Section titled “Reference”Environment variables
Section titled “Environment variables”| Variable | Secret | Required for | Notes |
|---|---|---|---|
META_APP_ID |
no | Meta | App ID from App settings › Basic |
META_APP_SECRET |
yes | Meta | App secret |
GOOGLE_ADS_CLIENT_ID |
no | Google Ads | OAuth client id |
GOOGLE_ADS_CLIENT_SECRET |
yes | Google Ads | OAuth client secret |
GOOGLE_ADS_DEVELOPER_TOKEN |
yes | Google Ads | Developer token of the manager account |
GOOGLE_ADS_LOGIN_CUSTOMER_ID |
no | Google Ads, optional | Manager account id, digits |
TIKTOK_APP_ID |
no | TikTok | App ID |
TIKTOK_APP_SECRET |
yes | TikTok | App secret |
ADS_OAUTH_REDIRECT_URI |
no | Optional | Overrides the ads callback (default <APP_ORIGIN>/oauth/ads/callback) |
GOOGLE_OAUTH_CLIENT_ID |
no | Google Calendar | OAuth client id |
GOOGLE_OAUTH_CLIENT_SECRET |
yes | Google Calendar | OAuth client secret |
APP_ORIGIN |
no | All | Public origin of the dashboard, used to build the redirect URIs |
AUTH_ENCRYPTION_KEY |
yes | Google Calendar grants and other stored secrets | Installation key (base64, 32 bytes) that encrypts stored grants and other secrets at rest |
Related credentials that are not OAuth apps
Section titled “Related credentials that are not OAuth apps”| Credential | Feature | Where it is documented |
|---|---|---|
CF_ZONE_ID, CF_API_TOKEN (with SSL and Certificates: Edit), TRACKING_CNAME_TARGET |
Custom tracking domains of the CNAME kind | CNAME domains |
CLOUDFLARE_DNS_API_TOKEN |
Automatic DNS records for sending and site domains | Optional tokens |
SYSTEM_EMAIL binding and SYSTEM_EMAIL_FROM |
Transactional system email of a self-hosted installation | Configuration |
The organic search statistics integration (the Integrations tab of the analytics settings) has no self-hosted app: it is available only in development (fake data) or through the managed offering.
Limits and permissions
Section titled “Limits and permissions”- Setting the secrets needs access to the Cloudflare account that runs the installation (or the Wrangler CLI logged in to it).
- Connecting ad accounts in the dashboard needs
analytics:configure. Connecting a Google calendar needsbooking:write; managing form connections needsforms:connections_manage. - Platform-side limits (test users, sandbox accounts, developer token levels) apply until each review is approved.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
| The card says Not configured on this installation. | The platform’s variables are missing on the core worker | Set them and redeploy. For Google Ads, all of client id, client secret and developer token are needed. |
The platform shows redirect_uri_mismatch (or a similar error) |
The registered redirect URI differs from the one the installation sends | Register exactly https://<your dashboard host>/oauth/ads/callback (or /oauth/google/callback); check APP_ORIGIN and ADS_OAUTH_REDIRECT_URI. |
| The callback lands but the connection is not created | The flow started on another origin (for example a workers.dev URL) than the callback |
Start the connection from the same host you registered. |
| Only some people can connect | The app is still in development, testing or sandbox mode | Add them as testers, or complete the platform review. |
Google Ads answers DEVELOPER_TOKEN_NOT_APPROVED |
The developer token is at Test account level | Apply for Basic access. |
| Google warns “unverified app” | The consent screen is not verified | Submit the app for verification, or keep using listed test users. |
| A connection shows Reconnect needed | The token expired or was revoked on the platform | Click Reconnect. |

