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