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