1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BenTools\Qivivo\OAuth2\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 League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
|
11
|
|
|
class Qivivo extends AbstractProvider |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
const SCOPE_USER_BASIC_INFORMATION = 'user_basic_information'; |
15
|
|
|
const SCOPE_READ_DEVICES = 'read_devices'; |
16
|
|
|
const SCOPE_READ_THERMOSTATS = 'read_thermostats'; |
17
|
|
|
const SCOPE_READ_WIRELESS_MODULES = 'read_wireless_modules'; |
18
|
|
|
const SCOPE_READ_PROGRAMMATION = 'read_programmation'; |
19
|
|
|
const SCOPE_UPDATE_PROGRAMMATION = 'update_programmation'; |
20
|
|
|
const SCOPE_READ_HOUSE_DATA = 'read_house_data'; |
21
|
|
|
const SCOPE_UPDATE_HOUSE_SETTINGS = 'update_house_settings'; |
22
|
|
|
|
23
|
|
|
use BearerAuthorizationTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get authorization url to begin OAuth flow |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
6 |
|
public function getBaseAuthorizationUrl() |
31
|
|
|
{ |
32
|
6 |
|
return 'https://account.qivivo.com'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get access token url to retrieve token |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
4 |
|
public function getBaseAccessTokenUrl(array $params) |
41
|
|
|
{ |
42
|
4 |
|
return 'https://account.qivivo.com/oauth/token'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get provider url to fetch user details |
47
|
|
|
* |
48
|
|
|
* @param AccessToken $token |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
* |
52
|
|
|
* @throws Exception\ResourceOwnerException |
53
|
|
|
*/ |
54
|
2 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
55
|
|
|
{ |
56
|
2 |
|
throw new Exception\ResourceOwnerException; |
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
|
4 |
|
protected function getDefaultScopes() |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
4 |
|
self::SCOPE_READ_DEVICES, |
71
|
4 |
|
self::SCOPE_READ_THERMOSTATS, |
72
|
4 |
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the string that should be used to separate scopes when building |
77
|
|
|
* the URL for requesting an access token. |
78
|
|
|
* |
79
|
|
|
* @return string Scope separator, defaults to ',' |
80
|
|
|
*/ |
81
|
6 |
|
protected function getScopeSeparator() |
82
|
|
|
{ |
83
|
6 |
|
return ' '; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Check a provider response for errors. |
88
|
|
|
* |
89
|
|
|
* @throws IdentityProviderException |
90
|
|
|
* @param ResponseInterface $response |
91
|
|
|
* @param string $data Parsed response data |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
2 |
|
protected function checkResponse(ResponseInterface $response, $data) |
95
|
|
|
{ |
96
|
2 |
|
$statusCode = $response->getStatusCode(); |
97
|
2 |
|
if ($statusCode >= 400) { |
98
|
|
|
throw new IdentityProviderException( |
99
|
|
|
isset($data['message']) ? $data['message'] : $response->getReasonPhrase(), |
100
|
|
|
$statusCode, |
101
|
|
|
$response |
|
|
|
|
102
|
|
|
); |
103
|
|
|
} |
104
|
2 |
|
} |
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
|
|
|
* @throws Exception\ResourceOwnerException |
113
|
|
|
*/ |
114
|
2 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
115
|
|
|
{ |
116
|
2 |
|
throw new Exception\ResourceOwnerException; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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: