Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

fix: use Basic Auth for X OAuth refresh token endpoint

Paulo Castellano3b8313e80434
diff --git a/app/Services/Social/XPublisher.php b/app/Services/Social/XPublisher.php
index c6a0b6b9f..d52d2e889 100644
--- a/app/Services/Social/XPublisher.php
+++ b/app/Services/Social/XPublisher.php
@@ -328,11 +328,12 @@ class XPublisher
throw new TokenExpiredException('No refresh token available for X account');
}
- $response = Http::asForm()->post("{$this->baseUrl}/2/oauth2/token", [
- 'grant_type' => 'refresh_token',
- 'refresh_token' => $account->refresh_token,
- 'client_id' => config('services.x.client_id'),
- ]);
+ $response = Http::asForm()
+ ->withBasicAuth(config('services.x.client_id'), config('services.x.client_secret'))
+ ->post("{$this->baseUrl}/2/oauth2/token", [
+ 'grant_type' => 'refresh_token',
+ 'refresh_token' => $account->refresh_token,
+ ]);
if ($response->failed()) {
$this->handleApiError($response, 'Failed to refresh X token');
diff --git a/tests/Unit/Services/Social/XPublisherTest.php b/tests/Unit/Services/Social/XPublisherTest.php
index d79b2359e..8e4c3ae80 100644
--- a/tests/Unit/Services/Social/XPublisherTest.php
+++ b/tests/Unit/Services/Social/XPublisherTest.php
@@ -124,7 +124,14 @@ test('x publisher refreshes token when expired', function () {
$this->publisher->publish($this->postPlatform);
Http::assertSent(function ($request) {
- return str_contains($request->url(), 'oauth2/token');
+ if (! str_contains($request->url(), 'oauth2/token')) {
+ return false;
+ }
+
+ // Verify Basic Auth is used for confidential client authentication
+ $authHeader = $request->header('Authorization')[0] ?? '';
+
+ return str_starts_with($authHeader, 'Basic ');
});
$this->socialAccount->refresh();