summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-02-26 18:30:00 +0100
committerGitHub <noreply@github.com>2018-02-26 18:30:00 +0100
commit8867629cf1b195b6c0e4616d8943f4fd31c42b7b (patch)
tree29f9677409501e78819e4c579e8e5e1c2f923888 /lib
parent4076c091951543289b310119e0f4e598143364be (diff)
parentd40c61a71a718db01df5a2b145be14641e2c5163 (diff)
downloadnextcloud-server-8867629cf1b195b6c0e4616d8943f4fd31c42b7b.tar.gz
nextcloud-server-8867629cf1b195b6c0e4616d8943f4fd31c42b7b.zip
Merge pull request #8359 from nextcloud/swift-v3
Support swift v3 authentication
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/ObjectStore/SwiftFactory.php34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/private/Files/ObjectStore/SwiftFactory.php b/lib/private/Files/ObjectStore/SwiftFactory.php
index 0df6fb6efcd..9513cdc3ab8 100644
--- a/lib/private/Files/ObjectStore/SwiftFactory.php
+++ b/lib/private/Files/ObjectStore/SwiftFactory.php
@@ -31,8 +31,9 @@ use OCP\Files\StorageAuthException;
use OCP\Files\StorageNotAvailableException;
use OCP\ICache;
use OpenStack\Common\Error\BadResponseError;
-use OpenStack\Identity\v2\Models\Token;
-use OpenStack\Identity\v2\Service;
+use OpenStack\Common\Auth\Token;
+use OpenStack\Identity\v2\Service as IdentityV2Service;
+use OpenStack\Identity\v3\Service as IdentityV3Service;
use OpenStack\OpenStack;
use OpenStack\Common\Transport\Utils as TransportUtils;
use Psr\Http\Message\RequestInterface;
@@ -77,30 +78,49 @@ class SwiftFactory {
// should only be true for tests
$this->params['autocreate'] = false;
}
- if (!isset($this->params['username']) && isset($this->params['user'])) {
- $this->params['username'] = $this->params['user'];
+ if (isset($this->params['user']) && is_array($this->params['user'])) {
+ $userName = $this->params['user']['name'];
+ } else {
+ if (!isset($this->params['username']) && isset($this->params['user'])) {
+ $this->params['username'] = $this->params['user'];
+ }
+ $userName = $this->params['username'];
}
if (!isset($this->params['tenantName']) && isset($this->params['tenant'])) {
$this->params['tenantName'] = $this->params['tenant'];
}
- $cacheKey = $this->params['username'] . '@' . $this->params['url'] . '/' . $this->params['bucket'];
+ $cacheKey = $userName . '@' . $this->params['url'] . '/' . $this->params['bucket'];
$token = $this->getCachedToken($cacheKey);
$hasToken = is_array($token) && (new \DateTimeImmutable($token['expires_at'])) > (new \DateTimeImmutable('now'));
if ($hasToken) {
$this->params['cachedToken'] = $token;
}
+
$httpClient = new Client([
'base_uri' => TransportUtils::normalizeUrl($this->params['url']),
'handler' => HandlerStack::create()
]);
- $authService = Service::factory($httpClient);
+ if (isset($this->params['user']) && isset($this->params['user']['name'])) {
+ return $this->auth(IdentityV3Service::factory($httpClient), $cacheKey);
+ } else {
+ return $this->auth(IdentityV2Service::factory($httpClient), $cacheKey);
+ }
+ }
+
+ /**
+ * @param IdentityV2Service|IdentityV3Service $authService
+ * @param string $cacheKey
+ * @return OpenStack
+ * @throws StorageAuthException
+ */
+ private function auth($authService, string $cacheKey) {
$this->params['identityService'] = $authService;
$this->params['authUrl'] = $this->params['url'];
$client = new OpenStack($this->params);
- if (!$hasToken) {
+ if (!isset($this->params['cachedToken'])) {
try {
$token = $authService->generateToken($this->params);
$this->cacheToken($token, $cacheKey);