1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SocialiteProviders\Manager\OAuth1; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\BadResponseException; |
6
|
|
|
use League\OAuth1\Client\Credentials\TemporaryCredentials; |
7
|
|
|
use League\OAuth1\Client\Credentials\TokenCredentials; |
8
|
|
|
|
9
|
|
|
abstract class Server extends \League\OAuth1\Client\Server\Server |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The custom parameters to be sent with the request. |
13
|
|
|
* |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
protected $parameters = []; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The scopes being requested. |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $scopes = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The separating character for the requested scopes. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $scopeSeparator = ','; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Retrieves token credentials by passing in the temporary credentials, |
34
|
|
|
* the temporary credentials identifier as passed back by the server |
35
|
|
|
* and finally the verifier code. |
36
|
|
|
* |
37
|
|
|
* @param TemporaryCredentials $temporaryCredentials |
38
|
|
|
* @param string $temporaryIdentifier |
39
|
|
|
* @param string $verifier |
40
|
|
|
* |
41
|
|
|
* @return TokenCredentials |
42
|
|
|
*/ |
43
|
|
|
public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier) |
44
|
|
|
{ |
45
|
|
|
if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) { |
46
|
|
|
throw new \InvalidArgumentException( |
47
|
|
|
'Temporary identifier passed back by server does not match that of stored temporary credentials. |
48
|
|
|
Potential man-in-the-middle.' |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$uri = $this->urlTokenCredentials(); |
53
|
|
|
$bodyParameters = array('oauth_verifier' => $verifier); |
54
|
|
|
|
55
|
|
|
$client = $this->createHttpClient(); |
56
|
|
|
|
57
|
|
|
$headers = $this->getHeaders($temporaryCredentials, 'POST', $uri, $bodyParameters); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
$response = $client->post($uri, $headers, $bodyParameters)->send(); |
61
|
|
|
} catch (BadResponseException $e) { |
62
|
|
|
return $this->handleTokenCredentialsBadResponse($e); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return [ |
|
|
|
|
66
|
|
|
'tokenCredentials' => $this->createTokenCredentials($response->getBody()), |
67
|
|
|
'credentialsResponseBody' => $response->getBody(), |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Set the scopes of the requested access. |
73
|
|
|
* |
74
|
|
|
* @param array $scopes |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function scopes(array $scopes) |
78
|
|
|
{ |
79
|
|
|
$this->scopes = array_unique(array_merge($this->scopes, $scopes)); |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set the custom parameters of the request. |
86
|
|
|
* |
87
|
|
|
* @param array $parameters |
88
|
|
|
* @return $this |
89
|
|
|
*/ |
90
|
|
|
public function with(array $parameters) |
91
|
|
|
{ |
92
|
|
|
$this->parameters = $parameters; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Format the given scopes. |
99
|
|
|
* |
100
|
|
|
* @param array $scopes |
101
|
|
|
* @param string $scopeSeparator |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
protected function formatScopes(array $scopes, $scopeSeparator) |
105
|
|
|
{ |
106
|
|
|
return implode($scopeSeparator, $scopes); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: