1
|
|
|
<?php namespace Stevenmaguire\OAuth2\Client\Provider; |
2
|
|
|
|
3
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
4
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
5
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
6
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class Uber extends AbstractProvider |
10
|
|
|
{ |
11
|
|
|
use BearerAuthorizationTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Default scopes |
15
|
|
|
* |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
public $defaultScopes = []; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Uber Api version |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
public $version = 'v1'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get authorization url to begin OAuth flow |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
9 |
|
public function getBaseAuthorizationUrl() |
33
|
|
|
{ |
34
|
9 |
|
return 'https://login.uber.com/oauth/authorize'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get access token url to retrieve token |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
43
|
|
|
{ |
44
|
12 |
|
return 'https://login.uber.com/oauth/token'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get provider url to fetch user details |
49
|
|
|
* |
50
|
|
|
* @param AccessToken $token |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
3 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
55
|
|
|
{ |
56
|
3 |
|
return 'https://api.uber.com/'.$this->version.'/me'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the default scopes used by this provider. |
61
|
|
|
* |
62
|
|
|
* This should not be a complete list of all scopes, but the minimum |
63
|
|
|
* required for the provider user interface! |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
6 |
|
protected function getDefaultScopes() |
68
|
|
|
{ |
69
|
6 |
|
return $this->defaultScopes; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the string that should be used to separate scopes when building |
74
|
|
|
* the URL for requesting an access token. |
75
|
|
|
* |
76
|
|
|
* @return string Scope separator, defaults to ' ' |
77
|
|
|
*/ |
78
|
9 |
|
protected function getScopeSeparator() |
79
|
|
|
{ |
80
|
9 |
|
return ' '; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Check a provider response for errors. |
85
|
|
|
* |
86
|
|
|
* @link https://developer.uber.com/v1/api-reference/ |
87
|
|
|
* @throws IdentityProviderException |
88
|
|
|
* @param ResponseInterface $response |
89
|
|
|
* @param string $data Parsed response data |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
9 |
|
protected function checkResponse(ResponseInterface $response, $data) |
93
|
|
|
{ |
94
|
9 |
|
$acceptableStatuses = [200, 201]; |
95
|
|
|
|
96
|
9 |
|
if (!in_array($response->getStatusCode(), $acceptableStatuses)) { |
97
|
3 |
|
throw new IdentityProviderException( |
98
|
3 |
|
$data['message'] ?: $response->getReasonPhrase(), |
99
|
3 |
|
$response->getStatusCode(), |
100
|
|
|
$response |
|
|
|
|
101
|
1 |
|
); |
102
|
|
|
} |
103
|
6 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Generate a user object from a successful user details request. |
107
|
|
|
* |
108
|
|
|
* @param object $response |
109
|
|
|
* @param AccessToken $token |
110
|
|
|
* @return League\OAuth2\Client\Provider\ResourceOwnerInterface |
111
|
|
|
*/ |
112
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
113
|
|
|
{ |
114
|
3 |
|
return new UberResourceOwner($response); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
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: