Skip to content

Commit

Permalink
Token caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Laszlo committed Dec 16, 2015
1 parent 4724261 commit a11142f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Wooxo/OvhSwiftLaravel/OvhSwiftLaravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public function __construct(){
'password' => Config::get('ovh-swift-laravel::config.password'),
'tenantId' => Config::get('ovh-swift-laravel::config.tenantId'),
));
$cacheFile = storage_path() . '/.opencloud_token';
// If the cache file exists, try importing it into the client
if (file_exists($cacheFile)) {
$data = unserialize(file_get_contents($cacheFile));
$this->client->importCredentials($data);
}
$token = $this->client->getTokenObject();
// If no token exists, or the current token is expired, re-authenticate and save the new token to disk
if (!$token || ($token && $token->hasExpired())) {
$this->client->authenticate();
file_put_contents($cacheFile, serialize($this->client->exportCredentials()));
}
$this->service = $this->client->objectStoreService('swift', Config::get('ovh-swift-laravel::config.region'), 'publicURL');
$this->container = $this->service->getContainer(Config::get('ovh-swift-laravel::config.container'));
}
Expand Down

0 comments on commit a11142f

Please sign in to comment.