You are here

public function LinkedinAuth::initSdk in Social Auth LinkedIn 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth::initSdk()
  2. 3.x src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth::initSdk()

File

src/Plugin/Network/LinkedinAuth.php, line 75

Class

LinkedinAuth
Defines Social Auth Linkedin Network Plugin.

Namespace

Drupal\social_auth_linkedin\Plugin\Network

Code

public function initSdk() {
  $class_name = '\\LinkedIn\\LinkedIn';
  if (!class_exists($class_name)) {
    throw new SocialApiException(sprintf('The PHP SDK for Linkedin Services could not be found. Class: %s.', $class_name));
  }

  /* @var \Drupal\social_auth_linkedin\Settings\LinkedinAuthSettings $settings */
  $settings = $this->settings;

  // Gets the absolute url of the callback.
  $redirect_uri = $this->urlGenerator
    ->generateFromRoute('social_auth_linkedin.callback', [], [
    'absolute' => TRUE,
  ]);

  // Creates a and sets data to Linkedin_Client object.
  $client = new LinkedIn([
    'api_key' => $settings
      ->getClientId(),
    'api_secret' => $settings
      ->getClientSecret(),
    'callback_url' => $redirect_uri,
  ]);
  return $client;
}