42 $this->swiftAuthUrl = $config[
'swiftAuthUrl'];
43 $this->swiftUser = $config[
'swiftUser'];
44 $this->swiftKey = $config[
'swiftKey'];
45 $this->swiftStorageUrl = $config[
'swiftStorageUrl'] ??
null;
47 $this->authTTL = $config[
'swiftAuthTTL'] ?? 15 * 60;
52 if ( !empty( $config[
'cacheAuthInfo'] ) ) {
53 $this->credentialCache = $this->srvCache;
72 if ( $this->authErrorTimestamp !==
null ) {
73 $interval = time() - $this->authErrorTimestamp;
74 if ( $interval < 60 ) {
76 'rejecting request since auth failure occurred {interval} seconds ago',
77 [
'interval' => $interval ]
81 $this->authErrorTimestamp =
null;
85 if ( !$this->authCreds ) {
86 $cacheKey = $this->getCredsCacheKey( $this->swiftUser );
87 $creds = $this->credentialCache->get( $cacheKey );
89 isset( $creds[
'auth_token'] ) &&
90 isset( $creds[
'storage_url'] ) &&
91 isset( $creds[
'expiry_time'] ) &&
92 $creds[
'expiry_time'] > time()
95 $this->setAuthCreds( $creds );
98 $this->refreshAuthentication();
102 return $this->authCreds;
126 [ $rcode, , $rhdrs, $rbody, ] = $this->http->run( [
128 'url' =>
"{$this->swiftAuthUrl}/v1.0",
130 'x-auth-user' => $this->swiftUser,
131 'x-auth-key' => $this->swiftKey
133 ], self::DEFAULT_HTTP_OPTIONS );
135 if ( $rcode >= 200 && $rcode <= 299 ) {
136 if ( isset( $rhdrs[
'x-auth-token-expires'] ) ) {
137 $ttl = intval( $rhdrs[
'x-auth-token-expires'] );
139 $ttl = $this->authTTL;
141 $expiryTime = time() + $ttl;
143 'auth_token' => $rhdrs[
'x-auth-token'],
144 'storage_url' => $this->swiftStorageUrl ?? $rhdrs[
'x-storage-url'],
145 'expiry_time' => $expiryTime,
147 $this->credentialCache->set(
148 $this->getCredsCacheKey( $this->swiftUser ),
152 } elseif ( $rcode === 401 ) {
153 $msg =
"HTTP {code} ({desc}) in '{func}': {err}";
156 'err' =>
"Authentication failed.",
157 'func' => __METHOD__,
159 $this->logger->error( $msg, $msgParams );
160 $this->authErrorTimestamp = time();
163 $msg =
"HTTP {code} ({desc}) in '{func}': {err}";
166 'err' =>
"HTTP return code: $rcode",
167 'func' => __METHOD__,
169 $this->logger->error( $msg, $msgParams );
170 $this->authErrorTimestamp = time();
173 $this->setAuthCreds( $creds );