diff --git a/lib/private/Files/ObjectStore/SwiftFactory.php b/lib/private/Files/ObjectStore/SwiftFactory.php
index 9513cdc3ab8b321672123d99763a9f7900793a71..eab3441ff2cf51d866e2619dffe0f6e34115ae4c 100644
--- a/lib/private/Files/ObjectStore/SwiftFactory.php
+++ b/lib/private/Files/ObjectStore/SwiftFactory.php
@@ -60,7 +60,12 @@ class SwiftFactory {
 	}
 
 	private function cacheToken(Token $token, string $cacheKey) {
-		$this->cache->set($cacheKey . '/token', json_encode($token));
+		if ($token instanceof \OpenStack\Identity\v3\Models\Token) {
+			$value = json_encode($token->export());
+		} else {
+			$value = json_encode($token);
+		}
+		$this->cache->set($cacheKey . '/token', $value);
 	}
 
 	/**