1 | <?php |
||
22 | class DooProvider extends AbstractProvider |
||
23 | { |
||
24 | use BearerAuthorizationTrait; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $apiUrl = 'https://api.doo.net/v1/'; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $uriAuthorize = 'oauth'; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $uriAccessToken = 'oauth'; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $uriResourceOwnerDetails = 'organizers/current'; |
||
45 | |||
46 | /** |
||
47 | * @var array|null |
||
48 | */ |
||
49 | private $scopes = null; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | private $scopeSeparator; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | private $responseError = 'error'; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | private $responseCode; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | private $responseResourceOwnerId = 'id'; |
||
70 | |||
71 | /** |
||
72 | * @param array $options |
||
73 | * @param array $collaborators |
||
74 | */ |
||
75 | 18 | public function __construct(array $options = [], array $collaborators = []) |
|
76 | { |
||
77 | 18 | $possible = $this->getConfigurableOptions(); |
|
78 | 18 | $configured = array_intersect_key($options, array_flip($possible)); |
|
79 | |||
80 | 18 | foreach ($configured as $key => $value) { |
|
81 | $this->$key = $value; |
||
82 | 12 | } |
|
83 | |||
84 | // Remove all options that are only used locally |
||
85 | 18 | $options = array_diff_key($options, $configured); |
|
86 | |||
87 | 18 | parent::__construct($options, $collaborators); |
|
88 | 18 | } |
|
89 | |||
90 | /** |
||
91 | * Returns all options that can be configured. |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | 18 | protected function getConfigurableOptions() |
|
108 | |||
109 | 18 | public function getBaseUri() |
|
113 | |||
114 | /** |
||
115 | * @inheritdoc |
||
116 | */ |
||
117 | 6 | public function getBaseAuthorizationUrl() |
|
118 | { |
||
119 | 6 | return $this->getBaseUri() . $this->uriAuthorize; |
|
120 | 2 | } |
|
121 | |||
122 | /** |
||
123 | * @inheritdoc |
||
124 | */ |
||
125 | 12 | public function getBaseAccessTokenUrl(array $params) |
|
126 | 2 | { |
|
127 | 12 | return $this->getBaseUri() . $this->uriAccessToken; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * @inheritdoc |
||
132 | */ |
||
133 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
||
137 | |||
138 | /** |
||
139 | * @inheritdoc |
||
140 | */ |
||
141 | 3 | public function getDefaultScopes() |
|
145 | |||
146 | /** |
||
147 | * @inheritdoc |
||
148 | */ |
||
149 | 3 | protected function getScopeSeparator() |
|
153 | |||
154 | /** |
||
155 | * @inheritdoc |
||
156 | */ |
||
157 | 9 | protected function checkResponse(ResponseInterface $response, $data) |
|
158 | { |
||
159 | 9 | if (!empty($data[$this->responseError])) { |
|
160 | $error = $data[$this->responseError]; |
||
161 | $code = $this->responseCode ? $data[$this->responseCode] : 0; |
||
162 | throw new IdentityProviderException($error, $code, $data); |
||
163 | } |
||
164 | 9 | } |
|
165 | |||
166 | /** |
||
167 | * @inheritdoc |
||
168 | */ |
||
169 | protected function createResourceOwner(array $response, AccessToken $token) |
||
173 | |||
174 | /** |
||
175 | * @param array $response |
||
176 | * @param AbstractGrant $grant |
||
177 | * @return AccessToken |
||
178 | */ |
||
179 | 9 | protected function createAccessToken(array $response, AbstractGrant $grant) |
|
193 | |||
194 | /** |
||
195 | * Returns the default headers used by this provider. |
||
196 | * |
||
197 | * Typically this is used to set 'Accept' or 'Content-Type' headers. |
||
198 | * |
||
199 | * @return array |
||
200 | */ |
||
201 | 9 | protected function getDefaultHeaders() |
|
207 | |||
208 | /** |
||
209 | * Builds request options used for requesting an access token. |
||
210 | * |
||
211 | * @param array $params |
||
212 | * @return array |
||
213 | */ |
||
214 | 9 | protected function getAccessTokenOptions(array $params) |
|
224 | |||
225 | /** |
||
226 | * Returns the request body for requesting an access token. |
||
227 | * |
||
228 | * @param array $params |
||
229 | * @return string |
||
230 | */ |
||
231 | 9 | protected function getAccessTokenBody(array $params) |
|
235 | |||
236 | 3 | public function getBearerAuthorizationHeader() |
|
241 | } |
||
242 |