1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mugnate\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
6
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
7
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
|
10
|
|
|
class Ecwid extends AbstractProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string Key used in a token response to identify the resource owner. |
14
|
|
|
*/ |
15
|
|
|
const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'store_id'; |
16
|
|
|
|
17
|
36 |
|
public function __construct(array $options = [], array $collaborators = []) |
18
|
|
|
{ |
19
|
36 |
|
if (empty($options['clientId'])) { |
20
|
3 |
|
throw new \InvalidArgumentException('The "clientId" option not set. Please set it.'); |
21
|
36 |
|
} elseif (empty($options['clientSecret'])) { |
22
|
|
|
throw new \InvalidArgumentException('The "clientSecret" option not set. Please set it.'); |
23
|
36 |
|
} elseif (empty($options['redirectUri'])) { |
24
|
|
|
throw new \InvalidArgumentException('The "redirectUri" option not set. Please set it.'); |
25
|
|
|
} |
26
|
|
|
|
27
|
36 |
|
parent::__construct($options, $collaborators); |
28
|
36 |
|
} |
29
|
|
|
|
30
|
6 |
|
public function getBaseAuthorizationUrl() |
31
|
|
|
{ |
32
|
6 |
|
return 'https://my.ecwid.com/api/oauth/authorize'; |
33
|
|
|
} |
34
|
|
|
|
35
|
18 |
|
public function getBaseAccessTokenUrl(array $params) |
36
|
|
|
{ |
37
|
18 |
|
return 'https://my.ecwid.com/api/oauth/token'; |
38
|
|
|
} |
39
|
|
|
|
40
|
9 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
41
|
|
|
{ |
42
|
9 |
|
return 'https://app.ecwid.com/api/v3/' .$token->getResourceOwnerId(). '/profile?token=' . $token->getToken(); |
43
|
|
|
} |
44
|
|
|
|
45
|
6 |
|
protected function getDefaultScopes() |
46
|
|
|
{ |
47
|
6 |
|
return ['read_store_profile']; |
48
|
|
|
} |
49
|
|
|
|
50
|
15 |
|
protected function checkResponse(ResponseInterface $response, $data) |
51
|
|
|
{ |
52
|
15 |
|
if (isset($data['error']) || $response->getStatusCode() != 200) { |
53
|
6 |
|
throw new IdentityProviderException($data['error'], $response->getStatusCode(), $response); |
|
|
|
|
54
|
|
|
} |
55
|
9 |
|
} |
56
|
|
|
|
57
|
9 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
58
|
|
|
{ |
59
|
9 |
|
return new EcwidStoreProfile($response); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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: