Skip to content

Commit 745c28a

Browse files
committed
Add username and password authentication to the Redis connection
1 parent b66ca6c commit 745c28a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Io/Factory.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,23 @@ public function createClient(string $uri): PromiseInterface
9696
// use `?password=secret` query or `user:secret@host` password form URL
9797
if (isset($args['password']) || isset($parts['pass'])) {
9898
$pass = $args['password'] ?? rawurldecode($parts['pass']); // @phpstan-ignore-line
99+
100+
$user = null;
101+
if (isset($args['username']) || isset($parts['user'])) {
102+
$user = $args['username'] ?? rawurldecode($parts['user']); // @phpstan-ignore-line
103+
}
104+
99105
\assert(\is_string($pass));
100-
$promise = $promise->then(function (StreamingClient $redis) use ($pass, $uri) {
101-
return $redis->callAsync('auth', $pass)->then(
106+
\assert($user === null || \is_string($user));
107+
108+
$promise = $promise->then(function (StreamingClient $redis) use ($user, $pass, $uri) {
109+
if ($user !== null) {
110+
$authPromise = $redis->callAsync('auth', $user, $pass);
111+
} else {
112+
$authPromise = $redis->callAsync('auth', $pass);
113+
}
114+
115+
return $authPromise->then(
102116
function () use ($redis) {
103117
return $redis;
104118
},
@@ -211,4 +225,4 @@ function (\Throwable $e) use ($redis, $uri) {
211225
// variable assignment needed for legacy PHPStan on PHP 7.1 only
212226
return $ret;
213227
}
214-
}
228+
}

0 commit comments

Comments
 (0)