|
1
|
|
|
<?php |
|
2
|
|
|
namespace Dokeop\OAuth2\Client\Provider; |
|
3
|
|
|
|
|
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 Dokeop extends AbstractProvider |
|
10
|
|
|
{ |
|
11
|
|
|
use BearerAuthorizationTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var string Key used in the access token response to identify the resource owner. |
|
15
|
|
|
*/ |
|
16
|
|
|
const ACCESS_TOKEN_RESOURCE_OWNER_ID = null; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
const BASE_DOKEOP_URL = 'https://www.dokeop.com'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $apiVersion = 'v1'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Constructs an OAuth 2.0 service provider. |
|
30
|
|
|
* |
|
31
|
|
|
* @param array $options An array of options to set on this provider. |
|
32
|
|
|
* Options include `clientId`, `clientSecret`, `redirectUri`, `state`, `apiVersion`. |
|
33
|
|
|
* Individual providers may introduce more options, as needed. |
|
34
|
|
|
* @param array $collaborators An array of collaborators that may be used to |
|
35
|
|
|
* override this provider's default behavior. Collaborators include |
|
36
|
|
|
* `grantFactory`, `requestFactory`, `httpClient`, and `randomFactory`. |
|
37
|
|
|
* Individual providers may introduce more collaborators, as needed. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(array $options = [], array $collaborators = []) |
|
40
|
|
|
{ |
|
41
|
|
|
parent::__construct($options, $collaborators); |
|
42
|
|
|
|
|
43
|
|
|
foreach ($options as $option => $value) { |
|
44
|
|
|
if (property_exists($this, $option)) { |
|
45
|
|
|
$this->{$option} = $value; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get authorization url to begin OAuth flow |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getBaseAuthorizationUrl() |
|
56
|
|
|
{ |
|
57
|
|
|
return self::BASE_DOKEOP_URL . '/oauth/authorize'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get access token url to retrieve token |
|
62
|
|
|
* |
|
63
|
|
|
* @param array $params |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getBaseAccessTokenUrl(array $params) |
|
68
|
|
|
{ |
|
69
|
|
|
return self::BASE_DOKEOP_URL . '/oauth/token'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get provider url to fetch user details |
|
74
|
|
|
* |
|
75
|
|
|
* @param AccessToken $token |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
80
|
|
|
{ |
|
81
|
|
|
return self::BASE_DOKEOP_URL . '/api/' . $this->apiVersion . '/athlete'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @link https://developers.dokeop.com/docs/authentication |
|
86
|
|
|
* |
|
87
|
|
|
* Get the default scopes used by this provider. |
|
88
|
|
|
* |
|
89
|
|
|
* This should not be a complete list of all scopes, but the minimum |
|
90
|
|
|
* required for the provider user interface! |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function getDefaultScopes() |
|
95
|
|
|
{ |
|
96
|
|
|
return ['profile:read event:read event:write']; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Check a provider response for errors. |
|
101
|
|
|
* |
|
102
|
|
|
* @throws IdentityProviderException |
|
103
|
|
|
* @param ResponseInterface $response |
|
104
|
|
|
* @param string $data Parsed response data |
|
105
|
|
|
* @return void |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function checkResponse(ResponseInterface $response, $data) |
|
108
|
|
|
{ |
|
109
|
|
|
if ($response->getStatusCode() >= 400) { |
|
110
|
|
|
throw new IdentityProviderException( |
|
111
|
|
|
$data['message'] ?: $response->getReasonPhrase(), |
|
112
|
|
|
$response->getStatusCode(), |
|
113
|
|
|
$response |
|
|
|
|
|
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Generate a user object from a successful user details request. |
|
120
|
|
|
* |
|
121
|
|
|
* @param array $response |
|
122
|
|
|
* @param AccessToken $token |
|
123
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface |
|
124
|
|
|
*/ |
|
125
|
|
|
protected function createResourceOwner(array $response, AccessToken $token) |
|
126
|
|
|
{ |
|
127
|
|
|
return new DokeopResourceOwner($response); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getBaseDokeopUrl() |
|
134
|
|
|
{ |
|
135
|
|
|
return self::BASE_DOKEOP_URL; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return string |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getApiVersion() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->apiVersion; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Returns the default headers used by this provider. |
|
148
|
|
|
* |
|
149
|
|
|
* Typically this is used to set 'Accept' or 'Content-Type' headers. |
|
150
|
|
|
* |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function getDefaultHeaders() |
|
154
|
|
|
{ |
|
155
|
|
|
return [ |
|
156
|
|
|
'Accept' => 'application/json', |
|
157
|
|
|
'Accept-Encoding' => 'gzip', |
|
158
|
|
|
]; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
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: