-
-
Save davereid/71abaa2a23e2e2e34361 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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