You are here

class LinkedInAuthManager in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  2. 8 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  3. 8.3 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  4. 8.4 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  5. 8.5 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  6. 8.6 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  7. 8.7 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager
  8. 8.8 modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php \Drupal\social_auth_linkedin\LinkedInAuthManager

Class LinkedInAuthManager.

@package Drupal\social_auth_linkedin

Hierarchy

Expanded class hierarchy of LinkedInAuthManager

2 files declare their use of LinkedInAuthManager
LinkedInAuthController.php in modules/custom/social_auth_linkedin/src/Controller/LinkedInAuthController.php
LinkedInLinkController.php in modules/custom/social_auth_linkedin/src/Controller/LinkedInLinkController.php
1 string reference to 'LinkedInAuthManager'
social_auth_linkedin.services.yml in modules/custom/social_auth_linkedin/social_auth_linkedin.services.yml
modules/custom/social_auth_linkedin/social_auth_linkedin.services.yml
1 service uses LinkedInAuthManager
social_auth_linkedin.auth_manager in modules/custom/social_auth_linkedin/social_auth_linkedin.services.yml
\Drupal\social_auth_linkedin\LinkedInAuthManager

File

modules/custom/social_auth_linkedin/src/LinkedInAuthManager.php, line 16

Namespace

Drupal\social_auth_linkedin
View source
class LinkedInAuthManager extends AuthManager {

  /**
   * {@inheritdoc}
   */
  public function getSocialNetworkKey() {
    return LinkedInAuthSettings::getSocialNetworkKey();
  }

  /**
   * {@inheritdoc}
   */
  public function setSdk($sdk) {
    if (!$sdk instanceof LinkedIn) {
      throw new InvalidArgumentException('SDK object should be instance of \\Happyr\\LinkedIn\\LinkedIn class');
    }
    $this->sdk = $sdk;
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthenticationUrl($type, array $scope = [
    'r_basicprofile',
    'r_emailaddress',
  ]) {
    return $this->sdk
      ->getLoginUrl([
      'redirect_uri' => $this
        ->getRedirectUrl($type),
      'scope' => implode(',', $scope),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getAccessToken($type = '') {
    try {
      $access_token = $this->sdk
        ->getAccessToken();
      return $access_token;
    } catch (LinkedInException $e) {
      $this->loggerFactory
        ->get('social_auth_linkedin')
        ->error('Could not get LinkedIn access token. LinkedInException: @message', [
        '@message' => $e
          ->getMessage(),
      ]);
      return NULL;
    }
    if ($access_token) {
      $this->sdk
        ->setAccessToken($access_token);
      return $access_token;
    }
    $this->loggerFactory
      ->get('social_auth_linkedin')
      ->error('Could not get LinkedIn access token. User cancelled the dialog in Facebook or return URL was not valid.');
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getProfile() {
    if (!$this->profile) {
      if (($profile = $this->sdk
        ->get('v1/people/~:(id,firstName,lastName,email-address,formattedName,pictureUrls::(original))')) && !isset($profile['errorCode'])) {
        $this->profile = $profile;
      }
    }
    return $this->profile;
  }

  /**
   * {@inheritdoc}
   */
  public function getProfilePicture() {
    if (!empty($this->profile['pictureUrls']['_total'])) {
      return end($this->profile['pictureUrls']['values']);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setAccessToken($access_token) {
    $this->sdk
      ->setAccessToken($access_token);
  }

  /**
   * {@inheritdoc}
   */
  public function getAccountId() {
    return isset($this->profile['id']) ? $this->profile['id'] : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getFirstName() {
    return isset($this->profile['firstName']) ? $this->profile['firstName'] : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getLastName() {
    return isset($this->profile['lastName']) ? $this->profile['lastName'] : NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuthManager::$entityFieldManager protected property
AuthManager::$fieldPicture protected property Contains the field definition with a profile picture.
AuthManager::$loggerFactory protected property
AuthManager::$profile protected property Contains object of a profile received from a social network.
AuthManager::$sdk protected property Object of SDK to work with API of social network.
AuthManager::$urlGenerator protected property
AuthManager::getPreferredResolution public function Determines preferred profile pic resolution from account settings. Overrides AuthManagerInterface::getPreferredResolution
AuthManager::getRedirectUrl public function Returns URL to authorize/registration depending on type. Overrides AuthManagerInterface::getRedirectUrl
AuthManager::getUsername public function Returns user on a social network if it possible. Overrides AuthManagerInterface::getUsername 1
AuthManager::setFieldPicture public function Set an instance of a field definition that contains picture. Overrides AuthManagerInterface::setFieldPicture
AuthManager::__construct public function AuthManager constructor.
LinkedInAuthManager::getAccessToken public function Reads user's access token from social network. Overrides AuthManagerInterface::getAccessToken
LinkedInAuthManager::getAccountId public function Returns an account ID on a social network. Overrides AuthManagerInterface::getAccountId
LinkedInAuthManager::getAuthenticationUrl public function Returns the login URL where user will be redirected for authentication. Overrides AuthManagerInterface::getAuthenticationUrl
LinkedInAuthManager::getFirstName public function Returns first name on a social network if it possible. Overrides AuthManagerInterface::getFirstName
LinkedInAuthManager::getLastName public function Returns last name on a social network if it possible. Overrides AuthManagerInterface::getLastName
LinkedInAuthManager::getProfile public function Returns object of a user profile. Overrides AuthManagerInterface::getProfile
LinkedInAuthManager::getProfilePicture public function Returns URL of a profile picture. Overrides AuthManagerInterface::getProfilePicture
LinkedInAuthManager::getSocialNetworkKey public function Returns key-name of a social network. Overrides AuthManagerInterface::getSocialNetworkKey
LinkedInAuthManager::setAccessToken public function Set access token to AuthManager to use it for API calls. Overrides AuthManagerInterface::setAccessToken
LinkedInAuthManager::setSdk public function Set instance of SDK. Overrides AuthManagerInterface::setSdk