1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\OAuth2\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth2\Token\StdOAuth2Token; |
6
|
|
|
use OAuth\Common\Http\Exception\TokenResponseException; |
7
|
|
|
use OAuth\Common\Http\Uri\Uri; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Linkedin service. |
11
|
|
|
* |
12
|
|
|
* @author Antoine Corcy <[email protected]> |
13
|
|
|
* @link http://developer.linkedin.com/documents/authentication |
14
|
|
|
*/ |
15
|
|
|
class Linkedin extends AbstractService |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Defined scopes |
19
|
|
|
* @link http://developer.linkedin.com/documents/authentication#granting |
20
|
|
|
*/ |
21
|
|
|
const SCOPE_R_BASICPROFILE = 'r_basicprofile'; |
22
|
|
|
const SCOPE_R_FULLPROFILE = 'r_fullprofile'; |
23
|
|
|
const SCOPE_R_EMAILADDRESS = 'r_emailaddress'; |
24
|
|
|
const SCOPE_R_NETWORK = 'r_network'; |
25
|
|
|
const SCOPE_R_CONTACTINFO = 'r_contactinfo'; |
26
|
|
|
const SCOPE_RW_NUS = 'rw_nus'; |
27
|
|
|
const SCOPE_RW_COMPANY_ADMIN = 'rw_company_admin'; |
28
|
|
|
const SCOPE_RW_GROUPS = 'rw_groups'; |
29
|
|
|
const SCOPE_W_MESSAGES = 'w_messages'; |
30
|
|
|
const SCOPE_W_SHARE = 'w_share'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected function init() |
36
|
|
|
{ |
37
|
|
|
$this->stateParameterInAuthUrl = true; |
38
|
|
|
|
39
|
|
|
if( $this->baseApiUri === null ) { |
|
|
|
|
40
|
|
|
$this->baseApiUri = new Uri('https://api.linkedin.com/v1/'); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function getAuthorizationEndpoint() |
48
|
|
|
{ |
49
|
|
|
return new Uri('https://www.linkedin.com/uas/oauth2/authorization'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getAccessTokenEndpoint() |
56
|
|
|
{ |
57
|
|
|
return new Uri('https://www.linkedin.com/uas/oauth2/accessToken'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
protected function getAuthorizationMethod() |
64
|
|
|
{ |
65
|
|
|
return static::AUTHORIZATION_METHOD_HEADER_BEARER; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
protected function parseAccessTokenResponse($responseBody) |
72
|
|
|
{ |
73
|
|
|
$data = json_decode($responseBody, true); |
74
|
|
|
|
75
|
|
|
if (null === $data || !is_array($data)) { |
76
|
|
|
throw new TokenResponseException('Unable to parse response.'); |
77
|
|
|
} elseif (isset($data['error'])) { |
78
|
|
|
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$token = new StdOAuth2Token(); |
82
|
|
|
$token->setAccessToken($data['access_token']); |
83
|
|
|
$token->setLifeTime($data['expires_in']); |
84
|
|
|
|
85
|
|
|
if (isset($data['refresh_token'])) { |
86
|
|
|
$token->setRefreshToken($data['refresh_token']); |
87
|
|
|
unset($data['refresh_token']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
unset($data['access_token']); |
91
|
|
|
unset($data['expires_in']); |
92
|
|
|
|
93
|
|
|
$token->setExtraParams($data); |
94
|
|
|
|
95
|
|
|
return $token; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|