refactor(social): use config for OAuth hosts everywhere

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.
This commit is contained in:
Paulo Castellano 2026-05-19 08:34:35 -03:00
parent d5e28e3d02
commit 1660084227
9 changed files with 10 additions and 10 deletions

View file

@ -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

View file

@ -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)

View file

@ -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'),

View file

@ -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'),

View file

@ -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'),

View file

@ -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

View file

@ -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 = [];

View file

@ -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',

View file

@ -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',