You are here

public function OpenIDConnectLinkedinClient::retrieveUserInfo in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x src/Plugin/OpenIDConnectClient/OpenIDConnectLinkedinClient.php \Drupal\openid_connect\Plugin\OpenIDConnectClient\OpenIDConnectLinkedinClient::retrieveUserInfo()

Retrieves user info: additional user profile data.

Parameters

string $access_token: Access token.

Return value

array|bool User profile information array, or FALSE if retrieval failed.

Overrides OpenIDConnectClientBase::retrieveUserInfo

File

src/Plugin/OpenIDConnectClient/OpenIDConnectLinkedinClient.php, line 64

Class

OpenIDConnectLinkedinClient
LinkedIn OpenID Connect client.

Namespace

Drupal\openid_connect\Plugin\OpenIDConnectClient

Code

public function retrieveUserInfo($access_token) {
  $userinfo = [];
  $info = parent::retrieveUserInfo($access_token);
  if ($info) {
    $userinfo['sub'] = isset($info['id']) ? $info['id'] : '';
    $userinfo['first_name'] = isset($info['localizedFirstName']) ? $info['localizedFirstName'] : '';
    $userinfo['last_name'] = isset($info['localizedLastName']) ? $info['localizedLastName'] : '';
    $userinfo['name'] = $userinfo['first_name'] . ' ' . $userinfo['last_name'];
    if (isset($info['profilePicture']['displayImage~']['elements'])) {

      // The picture was provided.
      $pictures = $info['profilePicture']['displayImage~']['elements'];

      // The last picture should have the largest picture of size 800x800 px.
      $last_picture = end($pictures);
      if (isset($last_picture['identifiers'][0]['identifier'])) {
        $userinfo['picture'] = $last_picture['identifiers'][0]['identifier'];
      }
    }
    else {

      // The picture was not provided.
      $userinfo['picture'] = '';
    }
  }

  // Get the email. It should always be provided.
  if ($email = $this
    ->retrieveUserEmail($access_token)) {
    $userinfo['email'] = $email;
  }
  return $userinfo;
}