Skip to content

refactor(socials): single credential resolver for all social abilities - #4001

Merged
chubes4 merged 1 commit into
mainfrom
refactor/socials-unify-credentials
Nov 18, 2026
Merged

chubes4 merged 1 commit into
mainfrom
refactor/socials-unify-credentials

Conversation

@chubes4

@chubes4 chubes4 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Every data-machine-socials ability, publish handler, CLI command, and REST endpoint now resolves its auth provider and access token through one implementation: inc/Auth/CredentialResolver.php. Nothing in inc/ builds its own AuthAbilities lookup or calls getProvider(), getProviderForHandler(), or get_valid_access_token() anymore. Only CredentialResolver and the *Auth.php provider classes do.

CredentialResolver API

  • provider( $platform, $label, $require_authenticated = true, $expected_class = null ): returns the provider or a WP_Error.
  • token( ... ): returns {provider, token} and gets a valid token, refreshing it if needed.
  • credentials( ... ): returns {provider, token, config} (used by Pinterest publish).
  • providerForHandler( $handler_slug, ... ): follows auth_provider_key (used by SocialPublishAbility).
  • optional( $platform ): never returns an error. Used by YouTube search, which falls back to an API key.
  • config( $provider ) and all() (replaces getAllProviders in RestApi).

AbstractSocialAbility::resolveProvider(), resolveAccessToken() and the new resolveCredentials() all delegate to the resolver. Static ability callbacks, handlers and CLI commands call CredentialResolver directly. Every per-class private auth helper is deleted: getAuthProvider, get_auth, get_provider, resolve_provider, resolve_auth_provider, get_access_token, FacebookGraphClient::auth(), the handler $auth properties, and the class_exists( AuthAbilities ) guards.

Behavior

  • Errors: every credential failure is now missing_auth with status 401, using one of two standard messages:
    • <Label> not authenticated: the provider is missing, has the wrong class, or (when required) is unauthenticated.
    • <Label> access token is missing or expired. Re-authorize in WP Admin > Data Machine > Settings.
  • Instagram: FetchInstagramAccountAbility used to return instagram_auth for missing credentials. It now returns missing_auth with status 401. Graph error codes 190 and 102 still return instagram_auth.
  • Authentication checks: callers that checked is_authenticated() before still require it. Callers that only checked that the provider exists pass false.
  • Class checks: callers that used an instanceof check pass that class. Instagram publish (previously a @var cast) and the Tumblr CLI now pass their class too, so PHPStan can narrow the type.
  • Provider methods: the same provider methods are still called afterwards (get_page_access_token / get_page_id, get_user_id, get_session, get_connection, get_instance / get_access_token, Pinterest config), and the same HTTP requests are made.
  • LinkedIn: LinkedInPublishAbility::upload_image() now receives the resolved token as a parameter instead of fetching it again.
  • Twitter connection checks: TwitterDeleteAbility and TwitterUpdateAbility now check get_connection() with is_wp_error(). It returns TwitterOAuth|WP_Error and is never falsy, so the old ! $connection guard let a WP_Error through. TwitterDeleteAbility also reads error details from both array and object API responses. PHPStan reported these once the provider was typed; they are fixed by narrowing the types, not by re-baselining.
  • PHPCS: the arrays in InstagramInsightsAbility were reformatted so the file passes PHPCS now that it is changed.
  • Twitter: TwitterUpdateAbility passes the resolved provider to retweet, unretweet, like and unlike instead of looking it up again inside each one.

Migrated classes (79)

  • Abilities\\AbstractSocialAbility
  • Abilities\\Bluesky\\BlueskyDeleteAbility
  • Abilities\\Bluesky\\BlueskyPublishAbility
  • Abilities\\Bluesky\\BlueskyReadAbility
  • Abilities\\Bluesky\\BlueskyUpdateAbility
  • Abilities\\Facebook\\FacebookAdsPromoteAbility
  • Abilities\\Facebook\\FacebookAdsReadAbility
  • Abilities\\Facebook\\FacebookAdsUpdateAbility
  • Abilities\\Facebook\\FacebookCommentReplyAbility
  • Abilities\\Facebook\\FacebookDeleteAbility
  • Abilities\\Facebook\\FacebookPublishAbility
  • Abilities\\Facebook\\FacebookReadAbility
  • Abilities\\Facebook\\FacebookUpdateAbility
  • Abilities\\Instagram\\FetchInstagramAccountAbility
  • Abilities\\Instagram\\InstagramAccountInsightsAbility
  • Abilities\\Instagram\\InstagramCommentReplyAbility
  • Abilities\\Instagram\\InstagramDeleteAbility
  • Abilities\\Instagram\\InstagramInsightsAbility
  • Abilities\\Instagram\\InstagramMessageSendAbility
  • Abilities\\Instagram\\InstagramPublishAbility
  • Abilities\\Instagram\\InstagramReadAbility
  • Abilities\\Instagram\\InstagramUpdateAbility
  • Abilities\\LinkedIn\\LinkedInDeleteAbility
  • Abilities\\LinkedIn\\LinkedInPublishAbility
  • Abilities\\LinkedIn\\LinkedInReadAbility
  • Abilities\\LinkedIn\\LinkedInUpdateAbility
  • Abilities\\Mastodon\\MastodonDeleteAbility
  • Abilities\\Mastodon\\MastodonPublishAbility
  • Abilities\\Mastodon\\MastodonReadAbility
  • Abilities\\Mastodon\\MastodonUpdateAbility
  • Abilities\\Pinterest\\PinterestAnalyticsAbility
  • Abilities\\Pinterest\\PinterestBoardsAbility
  • Abilities\\Pinterest\\PinterestDeleteAbility
  • Abilities\\Pinterest\\PinterestPublishAbility
  • Abilities\\Pinterest\\PinterestReadAbility
  • Abilities\\Pinterest\\PinterestUpdateAbility
  • Abilities\\SocialPublishAbility
  • Abilities\\Threads\\ThreadsDeleteAbility
  • Abilities\\Threads\\ThreadsPublishAbility
  • Abilities\\Threads\\ThreadsReadAbility
  • Abilities\\Threads\\ThreadsUpdateAbility
  • Abilities\\TikTok\\TikTokPublishAbility
  • Abilities\\TikTok\\TikTokReadAbility
  • Abilities\\Tumblr\\TumblrDeleteAbility
  • Abilities\\Tumblr\\TumblrEngageAbility
  • Abilities\\Tumblr\\TumblrPublishAbility
  • Abilities\\Tumblr\\TumblrReadAbility
  • Abilities\\Tumblr\\TumblrUpdateAbility
  • Abilities\\Twitter\\TwitterDeleteAbility
  • Abilities\\Twitter\\TwitterPublishAbility
  • Abilities\\Twitter\\TwitterReadAbility
  • Abilities\\Twitter\\TwitterUpdateAbility
  • Abilities\\YouTube\\YouTubeAccountAbility
  • Abilities\\YouTube\\YouTubeSearchAbility
  • Abilities\\YouTube\\YouTubeUploadAbility
  • Cli\\Commands\\BlueskyCommand
  • Cli\\Commands\\FacebookCommand
  • Cli\\Commands\\InstagramCommand
  • Cli\\Commands\\LinkedInCommand
  • Cli\\Commands\\MastodonCommand
  • Cli\\Commands\\RedditCommand
  • Cli\\Commands\\ThreadsCommand
  • Cli\\Commands\\TikTokCommand
  • Cli\\Commands\\TumblrCommand
  • Cli\\Commands\\TwitterCommand
  • Cli\\Commands\\YouTubeCommand
  • Handlers\\Bluesky\\Bluesky
  • Handlers\\Facebook\\Facebook
  • Handlers\\Facebook\\FacebookGraphClient
  • Handlers\\Instagram\\Instagram
  • Handlers\\LinkedIn\\LinkedIn
  • Handlers\\Mastodon\\Mastodon
  • Handlers\\Pinterest\\Pinterest
  • Handlers\\Threads\\Threads
  • Handlers\\TikTok\\TikTok
  • Handlers\\Tumblr\\Tumblr
  • Handlers\\Twitter\\Twitter
  • Handlers\\YouTube\\YouTube
  • RestApi

Tests

  • New tests/Unit/Auth/CredentialResolverTest.php covers: provider missing, unauthenticated, unauthenticated allowed, empty token (null, empty, whitespace), token OK (trimmed), class mismatch, class match, config, optional() and all().
  • New tests/Unit/Auth/PlatformCredentialSpotCheckTest.php has one spot check for each of the 12 platforms. With the platform's provider unregistered, each one returns missing_auth with status 401 and the standard message, and makes no HTTP request.
  • Updated FetchInstagramAccountAbilityTest::test_missing_auth_never_calls_http and InstagramReadAbilityTest::test_returns_error_when_provider_unavailable for the standard errors.
  • Smokes load the resolver. All 5 pass locally (for f in tests/*.php; do php $f; done).
  • php -l passes on every changed file.
  • PHPStan level 7 run on inc/ against main: no new findings, and 70 existing findings are gone. CI (Homeboy lint and tests) passes.

Exceptions

  • Mastodon still reads its token with MastodonAuth::get_access_token() after the resolver returns the provider. It stores a static instance token with no refresh path, and keeping that call keeps the provider calls the same as before.

Written by Extra Chill Bot (AI agent) on behalf of Chris Huber.

@chubes4
chubes4 force-pushed the refactor/socials-unify-credentials branch from 0872d88 to 7f8519a Compare November 18, 2026 21:00
@chubes4
chubes4 merged commit c42ae34 into main Nov 18, 2026
2 checks passed
@chubes4
chubes4 deleted the refactor/socials-unify-credentials branch November 18, 2026 21:14
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.

1 participant