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