1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\OAuth1\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth1\Token\StdOAuth1Token; |
6
|
|
|
use OAuth\Common\Http\Exception\TokenResponseException; |
7
|
|
|
use OAuth\Common\Http\Uri\Uri; |
8
|
|
|
use OAuth\OAuth1\Token\TokenInterface; |
9
|
|
|
|
10
|
|
|
class Yahoo extends AbstractService |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
public function init() |
16
|
|
|
{ |
17
|
|
|
if (null === $this->baseApiUri) { |
18
|
|
|
$this->baseApiUri = new Uri('https://social.yahooapis.com/v1/'); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritDoc} |
24
|
|
|
*/ |
25
|
|
|
public function getRequestTokenEndpoint() |
26
|
|
|
{ |
27
|
|
|
return new Uri('https://api.login.yahoo.com/oauth/v2/get_request_token'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function getAuthorizationEndpoint() |
34
|
|
|
{ |
35
|
|
|
return new Uri('https://api.login.yahoo.com/oauth/v2/request_auth'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function getAccessTokenEndpoint() |
42
|
|
|
{ |
43
|
|
|
return new Uri('https://api.login.yahoo.com/oauth/v2/get_token'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function refreshAccessToken(TokenInterface $token) |
50
|
|
|
{ |
51
|
|
|
$extraParams = $token->getExtraParams(); |
52
|
|
|
$bodyParams = array('oauth_session_handle' => $extraParams['oauth_session_handle']); |
53
|
|
|
|
54
|
|
|
$authorizationHeader = array( |
55
|
|
|
'Authorization' => $this->buildAuthorizationHeaderForAPIRequest( |
56
|
|
|
'POST', |
57
|
|
|
$this->getAccessTokenEndpoint(), |
58
|
|
|
$this->storage->retrieveAccessToken($this->service(), $this->account()), |
|
|
|
|
59
|
|
|
$bodyParams |
60
|
|
|
) |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
$headers = array_merge($authorizationHeader, $this->getExtraOAuthHeaders(), array()); |
66
|
|
|
|
67
|
|
|
$responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $bodyParams, $headers); |
68
|
|
|
|
69
|
|
|
$token = $this->parseAccessTokenResponse($responseBody); |
70
|
|
|
$this->storage->storeAccessToken($this->service(), $token, $this->account()); |
71
|
|
|
|
72
|
|
|
return $token; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
protected function parseRequestTokenResponse($responseBody) |
79
|
|
|
{ |
80
|
|
|
parse_str($responseBody, $data); |
81
|
|
|
|
82
|
|
|
if (null === $data || !is_array($data)) { |
83
|
|
|
throw new TokenResponseException('Unable to parse response.'); |
84
|
|
|
} elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') { |
85
|
|
|
throw new TokenResponseException('Error in retrieving token.'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->parseAccessTokenResponse($responseBody); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
protected function parseAccessTokenResponse($responseBody) |
95
|
|
|
{ |
96
|
|
|
parse_str($responseBody, $data); |
97
|
|
|
|
98
|
|
|
if (null === $data || !is_array($data)) { |
99
|
|
|
throw new TokenResponseException('Unable to parse response.'); |
100
|
|
|
} elseif (isset($data['error'])) { |
101
|
|
|
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$token = new StdOAuth1Token(); |
105
|
|
|
|
106
|
|
|
$token->setRequestToken($data['oauth_token']); |
107
|
|
|
$token->setRequestTokenSecret($data['oauth_token_secret']); |
108
|
|
|
$token->setAccessToken($data['oauth_token']); |
109
|
|
|
$token->setAccessTokenSecret($data['oauth_token_secret']); |
110
|
|
|
|
111
|
|
|
if (isset($data['oauth_expires_in'])) { |
112
|
|
|
$token->setLifetime($data['oauth_expires_in']); |
113
|
|
|
} else { |
114
|
|
|
$token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
unset($data['oauth_token'], $data['oauth_token_secret']); |
118
|
|
|
$token->setExtraParams($data); |
119
|
|
|
|
120
|
|
|
return $token; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.