1 | <?php |
||
38 | abstract class AbstractResourceOwner implements ResourceOwnerInterface |
||
39 | { |
||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $options = array(); |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $paths = array(); |
||
49 | |||
50 | /** |
||
51 | * @var HttpClientInterface |
||
52 | */ |
||
53 | protected $httpClient; |
||
54 | |||
55 | /** |
||
56 | * @var HttpUtils |
||
57 | */ |
||
58 | protected $httpUtils; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $name; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $state; |
||
69 | |||
70 | /** |
||
71 | * @var RequestDataStorageInterface |
||
72 | */ |
||
73 | protected $storage; |
||
74 | |||
75 | /** |
||
76 | * @param HttpClientInterface $httpClient Buzz http client |
||
77 | * @param HttpUtils $httpUtils Http utils |
||
78 | * @param array $options Options for the resource owner |
||
79 | * @param string $name Name for the resource owner |
||
80 | * @param RequestDataStorageInterface $storage Request token storage |
||
81 | */ |
||
82 | public function __construct(HttpClientInterface $httpClient, HttpUtils $httpUtils, array $options, $name, RequestDataStorageInterface $storage) |
||
108 | |||
109 | /** |
||
110 | * Gives a chance for extending providers to customize stuff |
||
111 | */ |
||
112 | public function configure() |
||
116 | |||
117 | /** |
||
118 | * {@inheritDoc} |
||
119 | */ |
||
120 | public function getName() |
||
124 | |||
125 | /** |
||
126 | * {@inheritDoc} |
||
127 | */ |
||
128 | public function setName($name) |
||
132 | |||
133 | /** |
||
134 | * {@inheritDoc} |
||
135 | */ |
||
136 | public function getOption($name) |
||
144 | |||
145 | /** |
||
146 | * Add extra paths to the configuration. |
||
147 | * |
||
148 | * @param array $paths |
||
149 | */ |
||
150 | public function addPaths(array $paths) |
||
154 | |||
155 | /** |
||
156 | * Refresh an access token using a refresh token. |
||
157 | * |
||
158 | * @param string $refreshToken Refresh token |
||
159 | * @param array $extraParameters An array of parameters to add to the url |
||
160 | * |
||
161 | * @return array Array containing the access token and it's 'expires_in' value, |
||
162 | * along with any other parameters returned from the authentication |
||
163 | * provider. |
||
164 | * |
||
165 | * @throws AuthenticationException If an OAuth error occurred or no access token is found |
||
166 | */ |
||
167 | public function refreshAccessToken($refreshToken, array $extraParameters = array()) |
||
171 | |||
172 | /** |
||
173 | * Revoke an OAuth access token or refresh token. |
||
174 | * |
||
175 | * @param string $token The token (access token or a refresh token) that should be revoked. |
||
176 | * |
||
177 | * @return Boolean Returns True if the revocation was successful, otherwise False. |
||
178 | * |
||
179 | * @throws AuthenticationException If an OAuth error occurred |
||
180 | */ |
||
181 | public function revokeToken($token) |
||
185 | |||
186 | /** |
||
187 | * Get the response object to return. |
||
188 | * |
||
189 | * @return UserResponseInterface |
||
190 | */ |
||
191 | protected function getUserResponse() |
||
200 | |||
201 | /** |
||
202 | * @param string $url |
||
203 | * @param array $parameters |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | protected function normalizeUrl($url, array $parameters = array()) |
||
216 | |||
217 | /** |
||
218 | * Performs an HTTP request |
||
219 | * |
||
220 | * @param string $url The url to fetch |
||
221 | * @param string|array $content The content of the request |
||
|
|||
222 | * @param array $headers The headers of the request |
||
223 | * @param string $method The HTTP method to use |
||
224 | * |
||
225 | * @return HttpResponse The response content |
||
226 | */ |
||
227 | protected function httpRequest($url, $content = null, $headers = array(), $method = null) |
||
228 | { |
||
229 | if (null === $method) { |
||
230 | $method = null === $content || '' === $content ? HttpRequestInterface::METHOD_GET : HttpRequestInterface::METHOD_POST; |
||
231 | } |
||
232 | |||
233 | $request = new HttpRequest($method, $url); |
||
234 | $response = new HttpResponse(); |
||
235 | |||
236 | $contentLength = 0; |
||
237 | if (is_string($content)) { |
||
238 | $contentLength = strlen($content); |
||
239 | } elseif (is_array($content)) { |
||
240 | $contentLength = strlen(implode('', $content)); |
||
241 | } |
||
242 | |||
243 | $headers = array_merge( |
||
244 | array( |
||
245 | 'User-Agent: HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle)', |
||
246 | 'Content-Length: ' . $contentLength, |
||
247 | ), |
||
248 | $headers |
||
249 | ); |
||
250 | |||
251 | $request->setHeaders($headers); |
||
252 | $request->setContent($content); |
||
253 | |||
254 | try { |
||
255 | $this->httpClient->send($request, $response); |
||
256 | } catch (ClientException $e) { |
||
257 | throw new HttpTransportException('Error while sending HTTP request', $this->getName(), $e->getCode(), $e); |
||
258 | } |
||
259 | |||
260 | return $response; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * Get the 'parsed' content based on the response headers. |
||
265 | * |
||
266 | * @param HttpMessageInterface $rawResponse |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | protected function getResponseContent(HttpMessageInterface $rawResponse) |
||
285 | |||
286 | /** |
||
287 | * Generate a non-guessable nonce value. |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | protected function generateNonce() |
||
295 | |||
296 | /** |
||
297 | * @param string $url |
||
298 | * @param array $parameters |
||
299 | * |
||
300 | * @return HttpResponse |
||
301 | */ |
||
302 | abstract protected function doGetTokenRequest($url, array $parameters = array()); |
||
303 | |||
304 | /** |
||
305 | * @param string $url |
||
306 | * @param array $parameters |
||
307 | * |
||
308 | * @return HttpResponse |
||
309 | */ |
||
310 | abstract protected function doGetUserInformationRequest($url, array $parameters = array()); |
||
311 | |||
312 | /** |
||
313 | * Configure the option resolver |
||
314 | * |
||
315 | * @param OptionsResolverInterface $resolver |
||
316 | */ |
||
317 | protected function configureOptions(OptionsResolverInterface $resolver) |
||
342 | } |
||
343 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.