1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SocialConnect project |
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
5
|
|
|
* @author: Bogdan Popa https://github.com/icex <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace SocialConnect\OAuth2\Provider; |
10
|
|
|
|
11
|
|
|
use SocialConnect\Common\ArrayHydrator; |
12
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
13
|
|
|
use SocialConnect\Common\Entity\User; |
14
|
|
|
|
15
|
|
|
class LinkedIn extends \SocialConnect\OAuth2\AbstractProvider |
16
|
|
|
{ |
17
|
|
|
const NAME = 'linkedin'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
4 |
|
public function getBaseUri() |
23
|
|
|
{ |
24
|
4 |
|
return 'https://api.linkedin.com/v1/'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
2 |
|
public function getAuthorizeUri() |
31
|
|
|
{ |
32
|
2 |
|
return 'https://www.linkedin.com/oauth/v2/authorization'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
2 |
|
public function getRequestTokenUri() |
39
|
|
|
{ |
40
|
2 |
|
return 'https://www.linkedin.com/oauth/v2/accessToken'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
3 |
|
public function getName() |
47
|
|
|
{ |
48
|
3 |
|
return self::NAME; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
3 |
|
public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void |
55
|
|
|
{ |
56
|
3 |
|
$query['format'] = 'json'; |
57
|
|
|
|
58
|
3 |
|
if ($accessToken) { |
59
|
3 |
|
$headers['Authorization'] = "Bearer {$accessToken->getToken()}"; |
60
|
|
|
} |
61
|
3 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
3 |
|
public function getIdentity(AccessTokenInterface $accessToken) |
67
|
|
|
{ |
68
|
3 |
|
$response = $this->request( |
69
|
3 |
|
'GET', |
70
|
3 |
|
'people/~:(id,first-name,last-name,email-address,picture-url,location:(name))', |
71
|
3 |
|
[], |
72
|
|
|
$accessToken |
73
|
|
|
); |
74
|
|
|
|
75
|
1 |
|
$hydrator = new ArrayHydrator([ |
76
|
1 |
|
'id' => 'id', |
77
|
|
|
'emailAddress' => 'email', |
78
|
|
|
'firstName' => 'firstname', |
79
|
|
|
'lastName' => 'lastname', |
80
|
|
|
'pictureUrl' => 'pictureURL', |
81
|
|
|
]); |
82
|
|
|
|
83
|
1 |
|
return $hydrator->hydrate(new User(), $response); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|