1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
6
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class Moves extends AbstractProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
const BASE_MOVES_URL = 'https://moves-app.com'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
const BASE_MOVES_API_URL = 'https://api.moves-app.com'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $apiAuthVersion = 'v1'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $apiVersion = '1.1'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructs an OAuth 2.0 service provider. |
33
|
|
|
* |
34
|
|
|
* @param array $options An array of options to set on this provider. |
35
|
|
|
* Options include `clientId`, `clientSecret`, `redirectUri`, `state`, `apiVersion`. |
36
|
|
|
* Individual providers may introduce more options, as needed. |
37
|
|
|
* @param array $collaborators An array of collaborators that may be used to |
38
|
|
|
* override this provider's default behavior. Collaborators include |
39
|
|
|
* `grantFactory`, `requestFactory`, `httpClient`, and `randomFactory`. |
40
|
|
|
* Individual providers may introduce more collaborators, as needed. |
41
|
|
|
*/ |
42
|
24 |
|
public function __construct(array $options = [], array $collaborators = []) |
43
|
|
|
{ |
44
|
24 |
|
parent::__construct($options, $collaborators); |
45
|
|
|
|
46
|
24 |
|
foreach ($options as $option => $value) { |
47
|
24 |
|
if (property_exists($this, $option)) { |
48
|
24 |
|
$this->{$option} = $value; |
49
|
16 |
|
} |
50
|
16 |
|
} |
51
|
24 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get authorization url to begin OAuth flow |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
12 |
|
public function getBaseAuthorizationUrl() |
59
|
|
|
{ |
60
|
12 |
|
return self::BASE_MOVES_API_URL . '/oauth/' . $this->apiAuthVersion . '/authorize'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get access token url to retrieve token |
65
|
|
|
* |
66
|
|
|
* @param array $params |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
15 |
|
public function getBaseAccessTokenUrl(array $params) |
71
|
|
|
{ |
72
|
15 |
|
return self::BASE_MOVES_API_URL . '/oauth/' . $this->apiAuthVersion . '/access_token'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get provider url to fetch user details |
77
|
|
|
* |
78
|
|
|
* @param AccessToken $token |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
6 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
83
|
|
|
{ |
84
|
6 |
|
return self::BASE_MOVES_API_URL . '/api/' . $this->apiVersion . '/user/profile?access_token=' . $token; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @link https://dev.moves-app.com/docs/authentication#scopes |
89
|
|
|
* Get the default scopes used by this provider. |
90
|
|
|
* |
91
|
|
|
* This should not be a complete list of all scopes, but the minimum |
92
|
|
|
* required for the provider user interface! |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
6 |
|
protected function getDefaultScopes() |
97
|
|
|
{ |
98
|
6 |
|
return ['default']; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Check a provider response for errors. |
103
|
|
|
* |
104
|
|
|
* @throws IdentityProviderException |
105
|
|
|
* @param ResponseInterface $response |
106
|
|
|
* @param string $data Parsed response data |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
12 |
|
protected function checkResponse(ResponseInterface $response, $data) |
110
|
|
|
{ |
111
|
12 |
|
if (isset($data['error'])) { |
112
|
3 |
|
throw new IdentityProviderException( |
113
|
3 |
|
$data['error'] ?: $response->getReasonPhrase(), |
114
|
3 |
|
$response->getStatusCode(), |
115
|
2 |
|
$response |
|
|
|
|
116
|
2 |
|
); |
117
|
|
|
} |
118
|
9 |
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Generate a user object from a successful user details request. |
122
|
|
|
* |
123
|
|
|
* @param array $response |
124
|
|
|
* @param AccessToken $token |
125
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface |
126
|
|
|
*/ |
127
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
128
|
|
|
{ |
129
|
3 |
|
return new MovesResourceOwner($response); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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: