Skip to content

Add Meta data deletion callbacks, Google revoke on removal and LinkedIn Page refresh - #520

Open
mainalisandeep062 wants to merge 2 commits into
trypostit:mainfrom
yoddha-social:feat/platform-compliance-callbacks
Open

mainalisandeep062 wants to merge 2 commits into
trypostit:mainfrom
yoddha-social:feat/platform-compliance-callbacks

Conversation

@mainalisandeep062

Copy link
Copy Markdown
Contributor

Closes #519.

Self-hosted installs run their own Meta, Google and LinkedIn apps, and each of these networks asks for something TryPost didn't have before an app can go Live or pass review. This PR adds all three parts of #519 together.

Meta: Deauthorize and Data Deletion callbacks

Each Meta app (Facebook, Instagram, Threads) has its own secret and its own callback fields, so each gets its own URLs on WEBHOOK_URL:

Setting in the app dashboard URL
Deauthorize callback URL /meta/{facebook,instagram,threads}/deauthorize
Data Deletion Request URL /meta/{facebook,instagram,threads}/data-deletion

.env.example lists them next to each app's keys.

Verification. SignedRequest verifies the signed_request with that app's secret: HMAC-SHA256 over the base64url payload, compared with hash_equals. The algorithm must be HMAC-SHA256. An empty secret or a malformed or unsigned request gets a 403.

Session. The two POST routes run withoutMiddleware('web'), like /.well-known, so Meta's server-to-server calls start no session and need no CSRF token.

Matching a callback to channels (SocialAccount::scopeAuthorizedByMetaUser):

  • Facebook app: meta.user_id on Facebook Page channels and on Instagram-through-Facebook channels. The Instagram-through-Facebook connect now stores the Facebook user it came from.
  • Instagram app: the channel's platform_user_id (Instagram Login's app-scoped id), or meta.ig_user_id. Meta's docs don't say which of the two the callback carries.
  • Threads app: platform_user_id.

Deauthorize. The matched channels are flagged token_expired, and each workspace owner gets one WorkspaceConnectionsDisconnected email listing them, as the daily check sends. There is no email per channel.

Data Deletion. The callback opens a data_deletion_requests row and answers with { url, confirmation_code }. The row holds the app, the code, a status and a count, and nothing that identifies the person. An encrypted queued job, DeleteMetaUserData, does the work:

  • An Instagram or Threads channel is the person's own account. It is removed the way Disconnect removes it, posts and media first. This uses the new DisconnectSocialAccount action, which SocialController@disconnect now calls too.
  • A Facebook Page, or an Instagram account connected through one, belongs to the business. The person was one of its admins, and one admin's deletion request shouldn't wipe a company's channel and post history for everyone. These channels keep their posts, but the person's id (meta.user_id, meta.user_token) and the tokens their login gave are erased, the channel is flagged for reconnection, and the owner is emailed as above. If you'd rather remove these channels too, it's a one-line change.

Status page. GET /meta/data-deletion/{code} (meta/DataDeletionStatus, on the auth layout) says whether the request is done. Its copy is in all 17 lang/*/accounts.php files.

Google: revoke on removal

When a YouTube or Google Business channel is removed (Disconnect, or a data deletion), SocialAccountObserver::deleted queues RevokeGoogleGrant after the commit. It is encrypted, because it carries the refresh token, and posts to {oauth_api}/revoke.

Google's docs say a revocation removes every scope the user granted to the project, for all of its clients. So the job skips the revoke while any other YouTube or Google Business channel, in any workspace, still has the same meta.google_user_id: other channels of the same login, or a location connected in another workspace. Without a google_user_id there's no way to tell, so nothing is revoked.

A 400 (already revoked or expired) counts as done. 5xx, 429 and connection errors are retried 3 times. A failed revoke never brings the channel back.

LinkedIn: Page profile storage

LinkedIn's Data Storage Requirements allow 8 weeks for the profile data of an organization that authenticated into the app.

  • Daily refresh. A new daily command, social:refresh-linkedin-pages, re-reads the name, vanity name and logo of each LinkedIn Page channel 7 weeks after it was last read. The new social_accounts.profile_refreshed_at column is set on every connect.
  • Clearing. A Page that can't be read (its token is dead, or the member no longer administers it) has those three fields cleared once they're 8 weeks old. The card then falls back to the network's name until it's reconnected.
  • Shared lookup. The organization lookup moved from LinkedInController to LinkedInOrganizations, so connect and refresh use the same request.
  • Member profiles are untouched. The authenticated member's basic profile has no storage limit, and §4.3 of the API Terms says not to refresh profile data on an automated schedule.

Not in this PR (worth a follow-up)

  • Instagram-through-Facebook channels connected before this change have no meta.user_id, so the Facebook callbacks can't match them until they're reconnected. The daily check still catches their dead tokens.
  • YouTube analytics after removal. The YouTube API Services policies (III.D.2.3, III.E.4) ask for a revoked user's API data to be deleted within 7 or 30 days. Disconnect keeps analytics publications on purpose (they are re-imported on reconnect), so YouTube statistics outlive the channel. Deleting them for YouTube would change that design, so I left it for you to decide.
  • Other revoke endpoints. X and TikTok have them. LinkedIn documents none, only introspection.
  • Workspace purge deletes channels through the database cascade, so no observer runs and no revoke is queued.
  • Signed request age. issued_at isn't checked, because Meta documents no window.

Tests

  • tests/Feature/Social/MetaCallbacksTest.php covers:
    • matching per app, across workspaces;
    • a wrong secret, a wrong algorithm, a malformed or missing request, and an app with no secret;
    • no session cookie on the callbacks;
    • the deletion JSON, and Instagram and Threads removal with posts;
    • Facebook unlinking that keeps posts and erases the login, and a repeated request finding nothing;
    • one email per workspace;
    • the status page.
  • tests/Feature/Jobs/RevokeGoogleGrantTest.php covers:
    • the dispatch on removal;
    • no dispatch for other networks or without a google_user_id;
    • the revoke call;
    • the skip while another channel shares the grant, for both platforms;
    • 400 as done, and a retry on 503.
  • tests/Feature/Actions/SocialAccount/RefreshLinkedInPageProfileTest.php covers:
    • a due refresh;
    • recent Pages and member channels left alone;
    • clearing at 8 weeks, but not before;
    • a Page the member no longer administers;
    • the connect timestamp.
  • InstagramFacebookControllerTest asserts the stored user_id.
  • tests/Pest.php fakes RevokeGoogleGrant next to BootstrapAccountAnalytics, so tests that remove Google channels never call Google.

Run on PostgreSQL: the new tests, plus tests/Feature/{Social,Channels,SocialAccount,Observers,Models,Jobs,Console,Commands,Actions,Mail}, LocalizationParityTest and tests/Unit. MySQL was not run locally. The meta->... lookups go through Laravel's JSON grammar.

I verified the signed-request format against Meta's Data Deletion Callback docs. Meta doesn't document the Instagram and Threads payloads separately, so I haven't checked them against a live app yet.

🤖 Generated with Claude Code

…In Page refresh

Self-hosted installs run their own Meta, Google and LinkedIn apps, and each
network asks for compliance endpoints before an app can go Live or pass review.

Meta: each app (Facebook, Instagram, Threads) gets a Deauthorize and a Data
Deletion callback on WEBHOOK_URL, verified with that app's secret and run
without the web middleware. Deauthorize flags the user's channels for
reconnection and emails each workspace owner once. Data Deletion answers with
a status page URL and confirmation code, and an encrypted job removes the
user's own Instagram and Threads channels like Disconnect does, while Facebook
Pages (and Instagram through a Page) keep their posts and lose the admin's id
and tokens. Instagram through Facebook now stores the Facebook user it came
from. Disconnect moves into the DisconnectSocialAccount action.

Google: removing a YouTube or Google Business channel queues an encrypted
revoke, skipped while another channel still holds the same Google user's
grant, since revoking ends the whole grant.

LinkedIn: a daily command re-reads LinkedIn Page names and logos after 7 weeks
and clears them at 8 weeks when they can no longer be read, per LinkedIn's
data storage requirements. Member profiles are left alone. The organization
lookup moves into LinkedInOrganizations.

Closes trypostit#519.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 05:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

mainalisandeep062 added a commit to yoddha-social/socialhq that referenced this pull request Nov 19, 2026
…In Page refresh (#42)

The platform compliance pack, also proposed to TryPost as
[trypostit#520](trypostit#520)
(issue trypostit#519). This branch carries the same commit,
cherry-picked, so we have it now. The full design is in trypostit#520's
description.

## What it adds

**Meta.** The Facebook, Instagram and Threads apps each get a
Deauthorize URL and a Data Deletion URL on `WEBHOOK_URL`:
- `/meta/{facebook,instagram,threads}/deauthorize`
- `/meta/{facebook,instagram,threads}/data-deletion`

Each callback is verified with that app's secret and runs with no
session or CSRF.
- **Deauthorize:** flags the person's channels for reconnection, with
one email per workspace.
- **Data Deletion:**
- Removes the person's own Instagram and Threads channels with their
posts.
- Facebook Pages, and Instagram connected through a Page, keep their
posts. They lose the person's id and tokens and need reconnecting.
  - Meta gets a status page URL and a confirmation code.

Paste these URLs into the Meta app's settings; `.env.example` lists
them. Meta wants a data deletion URL before an app can go Live.

**Google.** Removing a YouTube or Google Business channel revokes its
grant. The revoke is skipped while another channel uses the same Google
user, because revoking ends the whole grant.

**LinkedIn.** A daily `social:refresh-linkedin-pages` re-reads Page
names and logos after 7 weeks. It clears them at 8 weeks when they can
no longer be read, which is LinkedIn's storage limit for organization
data.

## Fork notes

- **PATCHES.md row 220** lists every TryPost file touched. Remove it
when trypostit#520 is merged and comes in with an intake.
- **Indonesian copy dropped.** TryPost's `lang/id` isn't in the fork, so
the new strings' `lang/id` copy is left out.
- **Conflicts.** No other PR is open, so rows 220+ are free.
- **Deploy:**
- Run the migrations (`data_deletion_requests`, and
`social_accounts.profile_refreshed_at`).
  - The scheduler picks up the new daily command.
- On the Meta app, set the two callback URLs (`publish.<domain>` must
reach `/meta/...` without Cloudflare Access in front, since Meta can't
sign in).

## Tests

Run locally on PostgreSQL in the Docker runner:
- `tests/Feature/Social` with the new tests: 563 passed
- `tests/Feature/SocialHq`: 609 passed
- Channels, SocialAccount, Observers, Models, LocalizationParity,
Console and Commands: 412 passed
- `tests/Unit`: 2022 passed, 11 skipped

Not run here:
- **Browser tests:** the new page has no browser test.
- **MySQL.**
- **Full `vue-tsc`:** the worktree had no Wayfinder output. The new page
itself has no type errors, and Prettier and ESLint are clean on it.
@paulocastellano

Copy link
Copy Markdown
Contributor

That's good @mainalisandeep062 i will check it soon!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Platform compliance callbacks: Meta deauthorize / data deletion, token revoke on channel removal, LinkedIn data storage

3 participants