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(linkedin): drop deprecated r_basicprofile from default scopes

Falconiere Barbosa410eb9612ef3
diff --git a/.env.example b/.env.example
index 6d4c31042..3ac86820a 100644
--- a/.env.example
+++ b/.env.example
@@ -103,6 +103,11 @@ LINKEDIN_CLIENT_ID=
LINKEDIN_CLIENT_SECRET=
LINKEDIN_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin/callback"
LINKEDIN_PAGE_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin-page/callback"
+# Optional: comma-separated extra OAuth scopes appended to the personal
+# LinkedIn connect flow. Use this if your LinkedIn dev app has legacy or
+# enterprise products approved — e.g. `r_basicprofile` re-enables
+# vanityName lookup via /v2/me. Leave empty for the safe default set.
+# LINKEDIN_EXTRA_SCOPES=r_basicprofile
# X / Twitter (https://developer.twitter.com)
X_CLIENT_ID=
diff --git a/app/Http/Controllers/Auth/LinkedInController.php b/app/Http/Controllers/Auth/LinkedInController.php
index 4dd59e4e5..c619d2106 100644
--- a/app/Http/Controllers/Auth/LinkedInController.php
+++ b/app/Http/Controllers/Auth/LinkedInController.php
@@ -26,7 +26,6 @@ class LinkedInController extends SocialController
'openid',
'profile',
'email',
- 'r_basicprofile',
'w_member_social',
];
@@ -42,7 +41,26 @@ class LinkedInController extends SocialController
$this->authorize('manageAccounts', $workspace);
- return $this->redirectToProvider($request, $this->driver, $this->scopes);
+ return $this->redirectToProvider($request, $this->driver, $this->resolveScopes());
+ }
+
+ /**
+ * Merge $this->scopes with any extra scopes the operator configured via
+ * `LINKEDIN_EXTRA_SCOPES` — comma-separated, e.g. `r_basicprofile`. Useful
+ * when the connected LinkedIn dev app has legacy or enterprise products
+ * not covered by the default Sign-In + Share-on-LinkedIn pair.
+ */
+ protected function resolveScopes(): array
+ {
+ $extra = (string) config('services.linkedin.extra_scopes', '');
+
+ if ($extra === '') {
+ return $this->scopes;
+ }
+
+ $extraScopes = array_filter(array_map('trim', explode(',', $extra)));
+
+ return array_values(array_unique([...$this->scopes, ...$extraScopes]));
}
public function callback(Request $request): View
diff --git a/config/services.php b/config/services.php
index b6c194cc1..f920d9edf 100644
--- a/config/services.php
+++ b/config/services.php
@@ -41,6 +41,12 @@ return [
'client_id' => env('LINKEDIN_CLIENT_ID'),
'client_secret' => env('LINKEDIN_CLIENT_SECRET'),
'redirect' => env('LINKEDIN_CLIENT_REDIRECT'),
+ // Comma-separated list of OAuth scopes to request beyond the defaults
+ // (openid, profile, email, w_member_social). Useful for apps with
+ // legacy or enterprise products approved — e.g. set
+ // `LINKEDIN_EXTRA_SCOPES=r_basicprofile` to re-enable vanityName
+ // lookup via /v2/me.
+ 'extra_scopes' => env('LINKEDIN_EXTRA_SCOPES'),
],
'linkedin-openid' => [
diff --git a/docker/.env.docker.example b/docker/.env.docker.example
index aaacd5fd2..e91739afe 100644
--- a/docker/.env.docker.example
+++ b/docker/.env.docker.example
@@ -90,6 +90,11 @@ LINKEDIN_CLIENT_ID=
LINKEDIN_CLIENT_SECRET=
LINKEDIN_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin/callback"
LINKEDIN_PAGE_CLIENT_REDIRECT="${APP_URL}/accounts/linkedin-page/callback"
+# Optional: comma-separated extra OAuth scopes appended to the personal
+# LinkedIn connect flow. Use this if your LinkedIn dev app has legacy or
+# enterprise products approved — e.g. `r_basicprofile` re-enables
+# vanityName lookup via /v2/me. Leave empty for the safe default set.
+# LINKEDIN_EXTRA_SCOPES=r_basicprofile
X_CLIENT_ID=
X_CLIENT_SECRET=
diff --git a/tests/Feature/Social/LinkedInControllerTest.php b/tests/Feature/Social/LinkedInControllerTest.php
index c95465a77..43fc5cf4c 100644
--- a/tests/Feature/Social/LinkedInControllerTest.php
+++ b/tests/Feature/Social/LinkedInControllerTest.php
@@ -39,6 +39,69 @@ test('linkedin connect redirects to oauth provider', function () {
expect(session('social_connect_workspace'))->toBe($this->workspace->id);
});
+test('linkedin connect requests the default scope set when LINKEDIN_EXTRA_SCOPES is unset', function () {
+ config(['services.linkedin.extra_scopes' => null]);
+
+ $captured = [];
+
+ $driverMock = Mockery::mock();
+ $driverMock->shouldReceive('scopes')
+ ->withArgs(function (array $scopes) use (&$captured) {
+ $captured = $scopes;
+
+ return true;
+ })
+ ->andReturnSelf();
+ $driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([
+ 'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1',
+ ]));
+
+ Socialite::shouldReceive('driver')
+ ->with('linkedin')
+ ->andReturn($driverMock);
+
+ $this->actingAs($this->user)
+ ->withHeader('X-Inertia', 'true')
+ ->get(route('app.social.linkedin.connect'));
+
+ expect($captured)->toEqualCanonicalizing([
+ 'openid', 'profile', 'email', 'w_member_social',
+ ]);
+});
+
+test('linkedin connect appends LINKEDIN_EXTRA_SCOPES to the default scope set', function () {
+ // Backward-compatibility: ops who have legacy products approved on
+ // their LinkedIn app (e.g. r_basicprofile) opt back in via env.
+ config(['services.linkedin.extra_scopes' => 'r_basicprofile, r_emailaddress']);
+
+ $captured = [];
+
+ $driverMock = Mockery::mock();
+ $driverMock->shouldReceive('scopes')
+ ->withArgs(function (array $scopes) use (&$captured) {
+ $captured = $scopes;
+
+ return true;
+ })
+ ->andReturnSelf();
+ $driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([
+ 'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1',
+ ]));
+
+ Socialite::shouldReceive('driver')
+ ->with('linkedin')
+ ->andReturn($driverMock);
+
+ $this->actingAs($this->user)
+ ->withHeader('X-Inertia', 'true')
+ ->get(route('app.social.linkedin.connect'));
+
+ expect($captured)->toEqualCanonicalizing([
+ 'openid', 'profile', 'email', 'w_member_social',
+ 'r_basicprofile', 'r_emailaddress',
+ ]);
+});
+
test('linkedin oauth callback creates account', function () {
session([
'social_connect_workspace' => $this->workspace->id,
@@ -99,7 +162,7 @@ test('linkedin oauth callback splits comma-separated approvedScopes before savin
// splits on space (the OAuth 2.0 default), so approvedScopes lands as
// a single-element array with the whole CSV inside. The save path
// must normalize back to individual tokens.
- $socialiteUser->approvedScopes = ['email,openid,profile,r_basicprofile,w_member_social'];
+ $socialiteUser->approvedScopes = ['email,openid,profile,w_member_social'];
Socialite::shouldReceive('driver')
->with('linkedin')
@@ -116,7 +179,7 @@ test('linkedin oauth callback splits comma-separated approvedScopes before savin
$account = SocialAccount::where('platform_user_id', 'abc123xyz')->first();
expect($account->scopes)->toEqualCanonicalizing([
- 'email', 'openid', 'profile', 'r_basicprofile', 'w_member_social',
+ 'email', 'openid', 'profile', 'w_member_social',
]);
});