Skip to content

Instantly share code, notes, and snippets.

@jamiehannaford
Created January 15, 2014 09:01
Show Gist options
  • Save jamiehannaford/8433002 to your computer and use it in GitHub Desktop.
Save jamiehannaford/8433002 to your computer and use it in GitHub Desktop.
cache token to bypass future auth requests
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
'apiKey' => 'bar'
));
$cacheFile = __DIR__ . '/.opencloudToken';
$token = $client->getTokenObject();
if (!$token || ($token && $token->hasExpired())) {
$client->authenticate();
$data = array(
'id' => $token->getId(),
'expires' => $token->getExpires()
);
file_put_contents($cacheFile, serialize($data));
}
if (file_exists($cacheFile)) {
$data = unserialize(file_get_contents($cacheFile));
$client->setToken($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment