Design note — Meta OAuth door (meta_ads)
Target registry item: C1b (OB-GAP-2 — a Meta system-user token needs an app the business can use; customers without a Meta app cannot complete the card self-serve). Status: design note only — NOT built. The meta_ads catalog row stays as measured on 2026-10-12 (access_token, ad_account_id required; pixel_id optional); nothing changes until the owner answers OB-GAP-2. CDoD points 1–14 are tracked in docs/reports/ONBOARDING_CONNECTORS_STATE.md.
Auth
Two custody paths into the same vault entry and the same adapter (MetaAdsAdapter, direct_connectors.py):
- Platform app door (new, this note) — Facebook Login for Business. A platform-owned Meta app of type Business on Track O, with a saved configuration whose token type is Business Integration System User (BISU): the token is tied to the merchant's business portfolio, grants only the assets the merchant explicitly selects in the dialog, and defaults to non-expiring — the right shape for server-to-server pulls (fetched 2026-10-12). Authorization-code grant; the server exchanges the code and writes the token to the vault. The merchant never generates or pastes a token. The ad account stays merchant-owned and merchant-granted (D2/D11); only the app is platform-owned, as with the Shopify install app.
- System-user token (typed card, kept). The current fields, unchanged, for a business that has its own app or an operator-guided, merchant-owned app.
Vault payload gains oauth_custody: "platform" | "tenant" and, on the platform path, the granted_assets readout (ad account ids and pixel/dataset ids the merchant selected — identifiers, never secrets). Masking is fail-closed (SCHEMA2_NON_SECRET_KEYS style): only allow-listed keys are echoed.
Door mechanics mirror shopify_install.py: tenant-bound state nonce; callback accepted only on nonce match; tenant from the verified session, never from the query; fixed registered redirect URI. Meta's rule that a user must grant every requested permission or the app receives none (fetched 2026-10-12) means the dialog requests the minimum set and nothing optional.
Vault-only per (tenant, provider); no environment fallback (the META_AD_ACCOUNT_ID env name is process-global and must never serve a tenant — resolve_provider_credentials docstring); vault error → 503 fail-closed; absent → merchant_credentials_not_configured; account_id in a sync body is a confirmation, never an override.
Fields (catalog row, when built)
Platform-custody path (the token field is replaced by a "Connect Meta" action):
| key | label | secret | required | pattern | help |
|---|---|---|---|---|---|
ad_account_id |
Ad account ID | no | yes | ^(act_)?\d+$ |
Numeric ad account id (with or without the act_ prefix) — not the pixel id. Must be one of the accounts you select in the Meta dialog. (pattern/help unchanged) |
pixel_id |
CAPI pixel / dataset ID | no | no | ^\d+$ |
Optional; a different identifier from the ad account. Collecting it arms nothing — the CAPI rail stays dry-run and flag-off. |
access_token |
— (written by the callback) | yes | yes (server-written) | — | BISU token; masked …tail on status. |
oauth_custody |
— (server-written) | no | yes | ^(platform\|tenant)$ |
Never a form field. |
Tenant-custody path: the row exactly as measured today.
Scopes
ads_read only (Ads Insights API read; it also unlocks the Conversions API send path, which this platform keeps dry-run and flag-off). ads_management is requested only where an owner ruling covers execution for that tenant — never in the default configuration. public_profile and email are granted automatically on user tokens and are not stored.
Data topics
Ad-account insights by date (impressions, clicks, spend, reach, frequency, actions, action_values) at account / campaign / ad set / ad level — the field list already in MetaAdsAdapter; granted-asset identifiers (binding check only). Graph API version resolved at call time from provider_versions (never a module literal).
Consent posture
| topic | posture |
|---|---|
| insights rows (aggregate) | de-personalised remainder; no person-level field in the source |
| granted assets | the merchant's own account/pixel identifiers; stored as declared ids only |
| CAPI send (separate rail) | hashed match keys OUT, unchanged by this note; MEASUREMENT_WRITEBACK=false and META_CAPI flag-off stay pinned |
Posture test in the TestD3ProcessingPosture style pins that no mapper output field is person-level.
Mapper target
Unchanged: MetaAdsAdapter → CanonicalRecord (campaign_performance) → gateway callback → canonical ingestion → mizoki_unified_data. No new store.
Failure modes → test-connection verdicts
| Failure | Verdict / fix |
|---|---|
| Merchant declined any requested permission (Meta grants none) | permissions_declined → "Approve every permission in the Meta dialog; the platform asks only for read access." |
Declared ad_account_id not among the assets granted in the dialog |
account_not_granted → "Select ad account <id> in the Meta dialog, or enter one of the accounts you granted." |
| App not yet approved for Advanced Access (tokens work only for app-role users) | 503 meta_app_access_not_configured — operator item (App Review pending); the card says "not yet available" rather than failing the merchant. |
| Token invalidated (asset removed from the integration, business change) | credentials_revoked → "Reconnect"; the entry is kept with healthy: false. |
| Vault read error | 503 fail-closed. |
| No vault entry | merchant_credentials_not_configured before any provider call. |
Flag
META_OAUTH_DOOR default OFF (source literal, ast-asserted). Flag OFF: typed path only; door routes 404. The card reuses the oauth.available readout pattern.
Owner / operator gates
- BLOCKED(owner) — OB-GAP-2. Build the Meta OAuth door (platform app on Track O, App Review)? Asked once in
ONBOARDING_CONNECTORS_STATE.md; no answer = BLOCKED. - Operator steps (Track O; platform app id/secret by env NAME only —
META_APP_ID,META_APP_SECRETfrom Secret Manager; never on a tenant form): 1. Create a Business-type Meta app; add Facebook Login for Business; create a configuration with token type BISU and permissionads_read; record its Configuration ID (a non-secret identifier served to the UI). 2. Meta App Review forads_readadvanced access — required to serve businesses the platform does not own or manage. The submission needs a use-case description with specific examples and a screencast showing the login flow and ad performance data (impressions, clicks, spend) in the product (fetched 2026-10-12). 3. Business Verification of the platform's business portfolio — required for all apps requesting Advanced Access (fetched 2026-10-12). 4. Advanced Access topublic_profilebefore the Login-for-Business app goes live; Ongoing Review to keep Advanced Access (fetched 2026-10-12). 5. Register the platform redirect URI; confirm the serving revision; live verification against a real merchant-owned ad account with date and revision recorded (CDoD point 14) beforeavailable/flag changes.
Vendor references
ads_readpermission reference — https://developers.facebook.com/docs/permissions/reference/ads_read — fetched 2026-10-12 (Insights + Conversions API; App Review items: use-case description + screencast; Business Verification required for Advanced Access).- Facebook Login for Business — https://developers.facebook.com/docs/facebook-login/facebook-login-for-business — fetched 2026-10-12 (Business-type app; configurations; BISU tokens non-expiring by default, authorization-code grant; all-or-nothing permission grant; Advanced Access + Ongoing Review).
- BISU token lifetime and invalidation rules in detail — not re-fetched from this sandbox on 2026-10-12.