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