Repository navigation
refactor(socials): single credential resolver for all social abilities - #4001
Merged
Merged
Conversation
chubes4
force-pushed
the
refactor/socials-unify-credentials
branch
from
November 18, 2026 21:00
0872d88 to
7f8519a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ininc/builds its ownAuthAbilitieslookup or callsgetProvider(),getProviderForHandler(), orget_valid_access_token()anymore. OnlyCredentialResolverand the*Auth.phpprovider classes do.CredentialResolver API
provider( $platform, $label, $require_authenticated = true, $expected_class = null ): returns the provider or aWP_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, ... ): followsauth_provider_key(used bySocialPublishAbility).optional( $platform ): never returns an error. Used by YouTube search, which falls back to an API key.config( $provider )andall()(replacesgetAllProvidersinRestApi).AbstractSocialAbility::resolveProvider(),resolveAccessToken()and the newresolveCredentials()all delegate to the resolver. Static ability callbacks, handlers and CLI commands callCredentialResolverdirectly. 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$authproperties, and theclass_exists( AuthAbilities )guards.Behavior
missing_authwith 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.FetchInstagramAccountAbilityused to returninstagram_authfor missing credentials. It now returnsmissing_authwith status 401. Graph error codes 190 and 102 still returninstagram_auth.is_authenticated()before still require it. Callers that only checked that the provider exists passfalse.instanceofcheck pass that class. Instagram publish (previously a@varcast) and the Tumblr CLI now pass their class too, so PHPStan can narrow the type.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.LinkedInPublishAbility::upload_image()now receives the resolved token as a parameter instead of fetching it again.TwitterDeleteAbilityandTwitterUpdateAbilitynow checkget_connection()withis_wp_error(). It returnsTwitterOAuth|WP_Errorand is never falsy, so the old! $connectionguard let aWP_Errorthrough.TwitterDeleteAbilityalso 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.InstagramInsightsAbilitywere reformatted so the file passes PHPCS now that it is changed.TwitterUpdateAbilitypasses the resolved provider to retweet, unretweet, like and unlike instead of looking it up again inside each one.Migrated classes (79)
Abilities\\AbstractSocialAbilityAbilities\\Bluesky\\BlueskyDeleteAbilityAbilities\\Bluesky\\BlueskyPublishAbilityAbilities\\Bluesky\\BlueskyReadAbilityAbilities\\Bluesky\\BlueskyUpdateAbilityAbilities\\Facebook\\FacebookAdsPromoteAbilityAbilities\\Facebook\\FacebookAdsReadAbilityAbilities\\Facebook\\FacebookAdsUpdateAbilityAbilities\\Facebook\\FacebookCommentReplyAbilityAbilities\\Facebook\\FacebookDeleteAbilityAbilities\\Facebook\\FacebookPublishAbilityAbilities\\Facebook\\FacebookReadAbilityAbilities\\Facebook\\FacebookUpdateAbilityAbilities\\Instagram\\FetchInstagramAccountAbilityAbilities\\Instagram\\InstagramAccountInsightsAbilityAbilities\\Instagram\\InstagramCommentReplyAbilityAbilities\\Instagram\\InstagramDeleteAbilityAbilities\\Instagram\\InstagramInsightsAbilityAbilities\\Instagram\\InstagramMessageSendAbilityAbilities\\Instagram\\InstagramPublishAbilityAbilities\\Instagram\\InstagramReadAbilityAbilities\\Instagram\\InstagramUpdateAbilityAbilities\\LinkedIn\\LinkedInDeleteAbilityAbilities\\LinkedIn\\LinkedInPublishAbilityAbilities\\LinkedIn\\LinkedInReadAbilityAbilities\\LinkedIn\\LinkedInUpdateAbilityAbilities\\Mastodon\\MastodonDeleteAbilityAbilities\\Mastodon\\MastodonPublishAbilityAbilities\\Mastodon\\MastodonReadAbilityAbilities\\Mastodon\\MastodonUpdateAbilityAbilities\\Pinterest\\PinterestAnalyticsAbilityAbilities\\Pinterest\\PinterestBoardsAbilityAbilities\\Pinterest\\PinterestDeleteAbilityAbilities\\Pinterest\\PinterestPublishAbilityAbilities\\Pinterest\\PinterestReadAbilityAbilities\\Pinterest\\PinterestUpdateAbilityAbilities\\SocialPublishAbilityAbilities\\Threads\\ThreadsDeleteAbilityAbilities\\Threads\\ThreadsPublishAbilityAbilities\\Threads\\ThreadsReadAbilityAbilities\\Threads\\ThreadsUpdateAbilityAbilities\\TikTok\\TikTokPublishAbilityAbilities\\TikTok\\TikTokReadAbilityAbilities\\Tumblr\\TumblrDeleteAbilityAbilities\\Tumblr\\TumblrEngageAbilityAbilities\\Tumblr\\TumblrPublishAbilityAbilities\\Tumblr\\TumblrReadAbilityAbilities\\Tumblr\\TumblrUpdateAbilityAbilities\\Twitter\\TwitterDeleteAbilityAbilities\\Twitter\\TwitterPublishAbilityAbilities\\Twitter\\TwitterReadAbilityAbilities\\Twitter\\TwitterUpdateAbilityAbilities\\YouTube\\YouTubeAccountAbilityAbilities\\YouTube\\YouTubeSearchAbilityAbilities\\YouTube\\YouTubeUploadAbilityCli\\Commands\\BlueskyCommandCli\\Commands\\FacebookCommandCli\\Commands\\InstagramCommandCli\\Commands\\LinkedInCommandCli\\Commands\\MastodonCommandCli\\Commands\\RedditCommandCli\\Commands\\ThreadsCommandCli\\Commands\\TikTokCommandCli\\Commands\\TumblrCommandCli\\Commands\\TwitterCommandCli\\Commands\\YouTubeCommandHandlers\\Bluesky\\BlueskyHandlers\\Facebook\\FacebookHandlers\\Facebook\\FacebookGraphClientHandlers\\Instagram\\InstagramHandlers\\LinkedIn\\LinkedInHandlers\\Mastodon\\MastodonHandlers\\Pinterest\\PinterestHandlers\\Threads\\ThreadsHandlers\\TikTok\\TikTokHandlers\\Tumblr\\TumblrHandlers\\Twitter\\TwitterHandlers\\YouTube\\YouTubeRestApiTests
tests/Unit/Auth/CredentialResolverTest.phpcovers: provider missing, unauthenticated, unauthenticated allowed, empty token (null, empty, whitespace), token OK (trimmed), class mismatch, class match, config,optional()andall().tests/Unit/Auth/PlatformCredentialSpotCheckTest.phphas one spot check for each of the 12 platforms. With the platform's provider unregistered, each one returnsmissing_authwith status 401 and the standard message, and makes no HTTP request.FetchInstagramAccountAbilityTest::test_missing_auth_never_calls_httpandInstagramReadAbilityTest::test_returns_error_when_provider_unavailablefor the standard errors.for f in tests/*.php; do php $f; done).php -lpasses on every changed file.inc/againstmain: no new findings, and 70 existing findings are gone. CI (Homeboy lint and tests) passes.Exceptions
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.