Skip to content

Instantly share code, notes, and snippets.

@davereid
Created July 9, 2015 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davereid/71abaa2a23e2e2e34361 to your computer and use it in GitHub Desktop.
Save davereid/71abaa2a23e2e2e34361 to your computer and use it in GitHub Desktop.
<?php
class Client extends GuzzleClient implements ClientInterface
{
/**
* {@inheritdoc}
*/
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = [])
{
$duration = isset($options['timeout']) ? $options['timeout'] : null;
$options['query']['token'] = $user->acquireToken($duration);
try {
$response = $this->send($this->createRequest($method, $url, $options));
return $response;
} catch (ApiException $exception) {
// If the token is invalid, we should delete it from storage so that a
// fresh token is fetched on the next request.
if ($exception->getCode() == 401) {
// Ensure the token will be deleted.
$user->invalidateToken();
}
throw $exception;
}
}
}
<?php
class Client extends GuzzleClient implements ClientInterface {
/**
* {@inheritdoc}
*/
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = []) {
$duration = isset($options['timeout']) ? $options['timeout'] : NULL;
$options['query']['token'] = $user->acquireToken($duration);
try {
$response = $this->send($this->createRequest($method, $url, $options));
return $response;
}
catch (ApiException $exception) {
// If the token is invalid, we should delete it from storage so that a
// fresh token is fetched on the next request.
if ($exception->getCode() == 401) {
// Ensure the token will be deleted.
$user->invalidateToken();
}
throw $exception;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment