Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Platform Linkedin Bundle Laravel Package

digitalstate/platform-linkedin-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. 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.

  3. 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.


Implementation Patterns

Workflow: OAuth Integration

  1. Initiate OAuth Flow Generate an authorization URL and redirect users:

    $authUrl = $linkedinService->getAuthorizationUrl(['state' => 'random_state_string']);
    return new RedirectResponse($authUrl);
    
  2. Handle Callback Capture the code from LinkedIn’s redirect and exchange it for an access token:

    $accessToken = $linkedinService->getAccessToken($code, $redirectUri);
    
  3. Fetch User Data Retrieve profile data using the access token:

    $userData = $linkedinService->getUserProfile($accessToken);
    

Workflow: Data Synchronization

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

Integration Tips

  • Event Listeners: Extend functionality by listening to linkedin.oauth.success or linkedin.profile.fetched events.
  • Configuration Overrides: Customize default settings via 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'
    
  • Dependency Injection: Inject LinkedinService directly into controllers/services:
    public function __construct(private LinkedinService $linkedinService) {}
    

Gotchas and Tips

Pitfalls

  1. Redirect URI Mismatch

    • LinkedIn’s OAuth requires an exact match for the redirect_uri (including http vs. https).
    • Fix: Double-check the URI in both LinkedIn Developer Portal and Oro config.
  2. Token Expiry

    • Access tokens expire (typically 60 days). Implement token refresh logic:
      try {
          $token = $linkedinService->getAccessToken($refreshToken);
      } catch (\Exception $e) {
          // Handle refresh failure (e.g., redirect to re-authenticate)
      }
      
  3. Scope Limitations

    • Request only necessary scopes (e.g., r_liteprofile, r_emailaddress) to avoid permission errors.
    • Example:
      $authUrl = $linkedinService->getAuthorizationUrl(['scope' => ['r_liteprofile']]);
      
  4. Rate Limits

    • LinkedIn API has strict rate limits. Cache responses aggressively:
      $cacheKey = 'linkedin_profile_' . $accessToken;
      if (!$profile = $cache->get($cacheKey)) {
          $profile = $linkedinService->getUserProfile($accessToken);
          $cache->set($cacheKey, $profile, 3600); // Cache for 1 hour
      }
      

Debugging

  • Enable Debug Mode: Set DIGITALSTATE_LINKEDIN_DEBUG=true in .env to log OAuth errors.
  • Check LinkedIn Developer Portal: Validate app status (e.g., "Live" mode) and IP/domain restrictions.
  • Test with Postman: Manually test API endpoints using your access token to isolate issues.

Extension Points

  1. 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']]);
    });
    
  2. Add Custom API Endpoints Extend the service to call LinkedIn’s API directly:

    $response = $linkedinService->makeApiRequest('GET', '/v2/people/~', $accessToken);
    
  3. Webhook Integration Use LinkedIn’s webhooks (e.g., for profile updates) by implementing a custom listener for the linkedin.webhook event.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route