From 166008422788b23ec2a4820cf9986f1520bc95fa Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 19 May 2026 08:34:35 -0300 Subject: [PATCH] refactor(social): use config for OAuth hosts everywhere MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier in the PR the new configs (linkedin.oauth_api, youtube.oauth_api, bluesky.default_service, mastodon.default_instance) were only read by ConnectionVerifier. The same URLs were still hardcoded in the publishers, analytics and the Bluesky auth controller — meaning a self-hosted user setting BLUESKY_DEFAULT_SERVICE or MASTODON_DEFAULT_INSTANCE in env would get split behavior: refresh/verify honor the override, publish/analytics don't. Routes all 10 remaining call sites through the same config values so the overrides actually work end-to-end. --- app/Http/Controllers/Auth/BlueskyController.php | 2 +- app/Services/Social/BlueskyPublisher.php | 4 ++-- app/Services/Social/LinkedInPageAnalytics.php | 2 +- app/Services/Social/LinkedInPagePublisher.php | 2 +- app/Services/Social/LinkedInPublisher.php | 2 +- app/Services/Social/MastodonAnalytics.php | 2 +- app/Services/Social/MastodonPublisher.php | 2 +- app/Services/Social/YouTubeAnalytics.php | 2 +- app/Services/Social/YouTubePublisher.php | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Auth/BlueskyController.php b/app/Http/Controllers/Auth/BlueskyController.php index 8ec10b91..4a74d99a 100644 --- a/app/Http/Controllers/Auth/BlueskyController.php +++ b/app/Http/Controllers/Auth/BlueskyController.php @@ -53,7 +53,7 @@ public function store(Request $request): View|RedirectResponse $this->authorize('manageAccounts', $workspace); - $service = 'https://bsky.social'; + $service = config('trypost.platforms.bluesky.default_service'); try { // Authenticate with Bluesky diff --git a/app/Services/Social/BlueskyPublisher.php b/app/Services/Social/BlueskyPublisher.php index f545e2df..ec18db80 100644 --- a/app/Services/Social/BlueskyPublisher.php +++ b/app/Services/Social/BlueskyPublisher.php @@ -26,7 +26,7 @@ public function publish(PostPlatform $postPlatform): array $content = $postPlatform->post->content ? app(ContentSanitizer::class)->sanitize($postPlatform->post->content, $postPlatform->platform) : null; $account = $postPlatform->socialAccount; - $service = $account->meta['service'] ?? 'https://bsky.social'; + $service = $account->meta['service'] ?? config('trypost.platforms.bluesky.default_service'); // Refresh token if needed if ($account->is_token_expired || $account->is_token_expiring_soon) { @@ -270,7 +270,7 @@ private function buildPostUrl(string $handle, string $postId): string public function refreshToken(SocialAccount $account): void { - $service = $account->meta['service'] ?? 'https://bsky.social'; + $service = $account->meta['service'] ?? config('trypost.platforms.bluesky.default_service'); // Try refresh first $response = $this->socialHttp()->withToken($account->refresh_token) diff --git a/app/Services/Social/LinkedInPageAnalytics.php b/app/Services/Social/LinkedInPageAnalytics.php index 8c809b9a..1c2c5b6a 100644 --- a/app/Services/Social/LinkedInPageAnalytics.php +++ b/app/Services/Social/LinkedInPageAnalytics.php @@ -240,7 +240,7 @@ private function refreshToken(SocialAccount $account): void throw new TokenExpiredException('No refresh token available for LinkedIn Page account'); } - $response = Http::asForm()->post('https://www.linkedin.com/oauth/v2/accessToken', [ + $response = Http::asForm()->post(config('trypost.platforms.linkedin.oauth_api').'/oauth/v2/accessToken', [ 'grant_type' => 'refresh_token', 'refresh_token' => $account->refresh_token, 'client_id' => config('services.linkedin-openid.client_id'), diff --git a/app/Services/Social/LinkedInPagePublisher.php b/app/Services/Social/LinkedInPagePublisher.php index 7c7ed796..d4a3c691 100644 --- a/app/Services/Social/LinkedInPagePublisher.php +++ b/app/Services/Social/LinkedInPagePublisher.php @@ -458,7 +458,7 @@ private function refreshToken(SocialAccount $account): void throw new TokenExpiredException('No refresh token available for LinkedIn Page account'); } - $response = Http::asForm()->post('https://www.linkedin.com/oauth/v2/accessToken', [ + $response = Http::asForm()->post(config('trypost.platforms.linkedin.oauth_api').'/oauth/v2/accessToken', [ 'grant_type' => 'refresh_token', 'refresh_token' => $account->refresh_token, 'client_id' => config('services.linkedin-openid.client_id'), diff --git a/app/Services/Social/LinkedInPublisher.php b/app/Services/Social/LinkedInPublisher.php index 37bdd435..540e37ae 100644 --- a/app/Services/Social/LinkedInPublisher.php +++ b/app/Services/Social/LinkedInPublisher.php @@ -439,7 +439,7 @@ private function refreshToken(SocialAccount $account): void throw new TokenExpiredException('No refresh token available for LinkedIn account'); } - $response = Http::asForm()->post('https://www.linkedin.com/oauth/v2/accessToken', [ + $response = Http::asForm()->post(config('trypost.platforms.linkedin.oauth_api').'/oauth/v2/accessToken', [ 'grant_type' => 'refresh_token', 'refresh_token' => $account->refresh_token, 'client_id' => config('services.linkedin.client_id'), diff --git a/app/Services/Social/MastodonAnalytics.php b/app/Services/Social/MastodonAnalytics.php index e071fbeb..606ab8a0 100644 --- a/app/Services/Social/MastodonAnalytics.php +++ b/app/Services/Social/MastodonAnalytics.php @@ -20,7 +20,7 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array return ['unsupported' => true, 'reason' => 'missing_post_id']; } - $instance = data_get($account->meta, 'instance', 'https://mastodon.social'); + $instance = data_get($account->meta, 'instance', config('trypost.platforms.mastodon.default_instance')); // Public posts: no auth needed. Our token only requests write scopes // (read:accounts + write:statuses + write:media), so attaching the diff --git a/app/Services/Social/MastodonPublisher.php b/app/Services/Social/MastodonPublisher.php index 66ac4b49..218d099d 100644 --- a/app/Services/Social/MastodonPublisher.php +++ b/app/Services/Social/MastodonPublisher.php @@ -25,7 +25,7 @@ public function publish(PostPlatform $postPlatform): array $content = $postPlatform->post->content ? app(ContentSanitizer::class)->sanitize($postPlatform->post->content, $postPlatform->platform) : null; $account = $postPlatform->socialAccount; - $instance = $account->meta['instance'] ?? 'https://mastodon.social'; + $instance = $account->meta['instance'] ?? config('trypost.platforms.mastodon.default_instance'); $medias = $postPlatform->post->mediaItems; $mediaIds = []; diff --git a/app/Services/Social/YouTubeAnalytics.php b/app/Services/Social/YouTubeAnalytics.php index 0d42997e..41f6a90c 100644 --- a/app/Services/Social/YouTubeAnalytics.php +++ b/app/Services/Social/YouTubeAnalytics.php @@ -168,7 +168,7 @@ private function refreshToken(SocialAccount $account): void throw new TokenExpiredException('No refresh token available for YouTube account'); } - $response = Http::asForm()->post('https://oauth2.googleapis.com/token', [ + $response = Http::asForm()->post(config('trypost.platforms.youtube.oauth_api').'/token', [ 'client_id' => config('services.google.client_id'), 'client_secret' => config('services.google.client_secret'), 'grant_type' => 'refresh_token', diff --git a/app/Services/Social/YouTubePublisher.php b/app/Services/Social/YouTubePublisher.php index 7525baa7..1f67c6d0 100644 --- a/app/Services/Social/YouTubePublisher.php +++ b/app/Services/Social/YouTubePublisher.php @@ -229,7 +229,7 @@ private function refreshToken(SocialAccount $account): void throw new TokenExpiredException('No refresh token available for YouTube account'); } - $response = Http::asForm()->post('https://oauth2.googleapis.com/token', [ + $response = Http::asForm()->post(config('trypost.platforms.youtube.oauth_api').'/token', [ 'client_id' => config('services.google.client_id'), 'client_secret' => config('services.google.client_secret'), 'grant_type' => 'refresh_token',