digitalstate/platform-linkedin-bundle
Install the Bundle
composer require digitalstate/platform-linkedin-bundle
Ensure the bundle is registered in config/bundles.php:
return [
// ...
DigitalState\Platform\LinkedinBundle\DigitalStatePlatformLinkedinBundle::class => ['all' => true],
];
Configure LinkedIn App Credentials Navigate to System → Configuration → Integrations → LinkedIn Settings in the Oro admin panel. Add your LinkedIn API credentials (Client ID, Client Secret, Redirect URI) and save.
First Use Case: OAuth Authentication Use the bundle’s service to initiate LinkedIn OAuth flow:
use DigitalState\Platform\LinkedinBundle\Service\LinkedinService;
$linkedinService = $this->container->get(LinkedinService::class);
$authUrl = $linkedinService->getAuthorizationUrl();
Redirect users to $authUrl to begin authentication.
Initiate OAuth Flow Generate an authorization URL and redirect users:
$authUrl = $linkedinService->getAuthorizationUrl(['state' => 'random_state_string']);
return new RedirectResponse($authUrl);
Handle Callback
Capture the code from LinkedIn’s redirect and exchange it for an access token:
$accessToken = $linkedinService->getAccessToken($code, $redirectUri);
Fetch User Data Retrieve profile data using the access token:
$userData = $linkedinService->getUserProfile($accessToken);
Use the bundle as a datasource for user profiles or CRM data:
// Example: Sync LinkedIn profile to Oro entity
$userProfile = $linkedinService->getUserProfile($accessToken);
$oroUser = $this->oroUserManager->findUserByEmail($userProfile['email']);
// Update or create Oro user with LinkedIn data
linkedin.oauth.success or linkedin.profile.fetched events.config/packages/digitalstate_platform_linkedin.yaml:
digitalstate_platform_linkedin:
client_id: 'your_custom_id'
client_secret: 'your_custom_secret'
redirect_uri: 'https://your-app.com/linkedin/callback'
LinkedinService directly into controllers/services:
public function __construct(private LinkedinService $linkedinService) {}
Redirect URI Mismatch
redirect_uri (including http vs. https).Token Expiry
try {
$token = $linkedinService->getAccessToken($refreshToken);
} catch (\Exception $e) {
// Handle refresh failure (e.g., redirect to re-authenticate)
}
Scope Limitations
r_liteprofile, r_emailaddress) to avoid permission errors.$authUrl = $linkedinService->getAuthorizationUrl(['scope' => ['r_liteprofile']]);
Rate Limits
$cacheKey = 'linkedin_profile_' . $accessToken;
if (!$profile = $cache->get($cacheKey)) {
$profile = $linkedinService->getUserProfile($accessToken);
$cache->set($cacheKey, $profile, 3600); // Cache for 1 hour
}
DIGITALSTATE_LINKEDIN_DEBUG=true in .env to log OAuth errors.Custom Profile Mapping Override the default profile data mapping in a compiler pass:
use DigitalState\Platform\LinkedinBundle\Event\LinkedinProfileEvent;
$eventDispatcher->addListener(LinkedinProfileEvent::PROFILE_FETCHED, function (LinkedinProfileEvent $event) {
$event->setData(['custom_field' => $event->getData()['firstName'] . ' ' . $event->getData()['lastName']]);
});
Add Custom API Endpoints Extend the service to call LinkedIn’s API directly:
$response = $linkedinService->makeApiRequest('GET', '/v2/people/~', $accessToken);
Webhook Integration
Use LinkedIn’s webhooks (e.g., for profile updates) by implementing a custom listener for the linkedin.webhook event.
How can I help you explore Laravel packages today?