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