| 1 |
<?php |
| 2 |
/*! |
| 3 |
* Hybridauth |
| 4 |
* https://hybridauth.github.io | https://github.com/hybridauth/hybridauth |
| 5 |
* (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Hybridauth\Provider; |
| 9 |
|
| 10 |
use Hybridauth\Adapter\OAuth2; |
| 11 |
use Hybridauth\Data; |
| 12 |
use Hybridauth\Exception\UnexpectedApiResponseException; |
| 13 |
use Hybridauth\User; |
| 14 |
|
| 15 |
/** |
| 16 |
* LinkedIn OAuth2 provider adapter. |
| 17 |
*/ |
| 18 |
class LinkedInOpenID extends OAuth2 |
| 19 |
{ |
| 20 |
/** |
| 21 |
* {@inheritdoc} |
| 22 |
*/ |
| 23 |
protected $scope = 'openid profile email'; |
| 24 |
|
| 25 |
/** |
| 26 |
* {@inheritdoc} |
| 27 |
*/ |
| 28 |
protected $apiBaseUrl = 'https://api.linkedin.com/v2/'; |
| 29 |
|
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
protected $authorizeUrl = 'https://www.linkedin.com/oauth/v2/authorization'; |
| 34 |
|
| 35 |
/** |
| 36 |
* {@inheritdoc} |
| 37 |
*/ |
| 38 |
protected $accessTokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken'; |
| 39 |
|
| 40 |
/** |
| 41 |
* {@inheritdoc} |
| 42 |
*/ |
| 43 |
protected $apiDocumentation = 'https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication'; |
| 44 |
|
| 45 |
/** |
| 46 |
* {@inheritdoc} |
| 47 |
*/ |
| 48 |
protected function initialize() |
| 49 |
{ |
| 50 |
parent::initialize(); |
| 51 |
|
| 52 |
if ($this->isRefreshTokenAvailable()) { |
| 53 |
$this->tokenRefreshParameters += [ |
| 54 |
'client_id' => $this->clientId, |
| 55 |
'client_secret' => $this->clientSecret |
| 56 |
]; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* {@inheritdoc} |
| 62 |
*/ |
| 63 |
public function getUserProfile() |
| 64 |
{ |
| 65 |
|
| 66 |
$response = $this->apiRequest('/userinfo', 'GET', []); |
| 67 |
$data = new Data\Collection($response); |
| 68 |
|
| 69 |
if (!$data->exists('sub')) { |
| 70 |
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
| 71 |
} |
| 72 |
|
| 73 |
$userProfile = new User\Profile(); |
| 74 |
|
| 75 |
$userProfile->firstName = $data->get('given_name'); |
| 76 |
$userProfile->lastName = $data->get('family_name'); |
| 77 |
$userProfile->identifier = $data->get('sub'); |
| 78 |
$userProfile->email = $data->get('email'); |
| 79 |
$userProfile->emailVerified = $data->get('email_verified'); |
| 80 |
$userProfile->displayName = $data->get('name'); |
| 81 |
$userProfile->photoURL = $data->get('picture'); |
| 82 |
|
| 83 |
return $userProfile; |
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|