Skip to content

Instantly share code, notes, and snippets.

@icewind1991
Created January 15, 2020 09:42
Show Gist options
  • Save icewind1991/3f3088c17917c783ceb21d002e966727 to your computer and use it in GitHub Desktop.
Save icewind1991/3f3088c17917c783ceb21d002e966727 to your computer and use it in GitHub Desktop.
From d71816ff1ed6d44b92111ed56b066a5e8ae43eda Mon Sep 17 00:00:00 2001
From: Robin Appelman <robin@icewind.nl>
Date: Wed, 15 Jan 2020 10:36:36 +0100
Subject: [PATCH] fix token on first auth
Signed-off-by: Robin Appelman <robin@icewind.nl>
---
lib/private/Files/ObjectStore/SwiftFactory.php | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lib/private/Files/ObjectStore/SwiftFactory.php b/lib/private/Files/ObjectStore/SwiftFactory.php
index 97c64fe81b..a20d2cdf3b 100644
--- a/lib/private/Files/ObjectStore/SwiftFactory.php
+++ b/lib/private/Files/ObjectStore/SwiftFactory.php
@@ -81,10 +81,11 @@ class SwiftFactory {
private function cacheToken(Token $token, string $serviceUrl, string $cacheKey) {
if ($token instanceof \OpenStack\Identity\v3\Models\Token) {
// for v3 the catalog is cached as part of the token, so no need to cache $serviceUrl separately
- $value = json_encode($token->export());
+ $value = $token->export();
+ $this->params['cachedToken'] = $value;
} else {
/** @var \OpenStack\Identity\v2\Models\Token $token */
- $value = json_encode([
+ $value = [
'serviceUrl' => $serviceUrl,
'token' => [
'issued_at' => $token->issuedAt->format('c'),
@@ -92,15 +93,16 @@ class SwiftFactory {
'id' => $token->id,
'tenant' => $token->tenant
]
- ]);
+ ];
+ $this->params['cachedToken'] = $value['token'];
}
- $this->cache->set($cacheKey . '/token', $value);
+ $this->cache->set($cacheKey . '/token', json_encode($value));
}
public function getHeaders() {
$headers = [ 'Cache-Control' => [ 'no-cache' ] ];
- if (!is_null($this->params['cachedToken'])) {
+ if (isset($this->params['cachedToken'])) {
$headers += [ 'X-Auth-Token' => [ $this->params['cachedToken']['id'] ] ];
}
--
2.24.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment