Commit 7965f122 authored by Marc Gravell's avatar Marc Gravell

allow auth with user (redis 6)

parent 6b20e13f
......@@ -76,6 +76,7 @@ internal const string
HighPrioritySocketThreads = "highPriorityThreads",
KeepAlive = "keepAlive",
ClientName = "name",
User = "user",
Password = "password",
PreserveAsyncOrder = "preserveAsyncOrder",
Proxy = "proxy",
......@@ -104,6 +105,7 @@ internal const string
DefaultDatabase,
HighPrioritySocketThreads,
KeepAlive,
User,
Password,
PreserveAsyncOrder,
Proxy,
......@@ -305,6 +307,11 @@ public int ConnectTimeout
public int KeepAlive { get { return keepAlive.GetValueOrDefault(-1); } set { keepAlive = value; } }
#pragma warning restore RCS1128 // Use coalesce expression.
/// <summary>
/// The user to use to authenticate with the server.
/// </summary>
public string User { get; set; }
/// <summary>
/// The password to use to authenticate with the server.
/// </summary>
......@@ -441,6 +448,7 @@ public ConfigurationOptions Clone()
allowAdmin = allowAdmin,
defaultVersion = defaultVersion,
connectTimeout = connectTimeout,
User = User,
Password = Password,
tieBreaker = tieBreaker,
writeBuffer = writeBuffer,
......@@ -505,6 +513,7 @@ public string ToString(bool includePassword)
Append(sb, OptionKeys.AllowAdmin, allowAdmin);
Append(sb, OptionKeys.Version, defaultVersion);
Append(sb, OptionKeys.ConnectTimeout, connectTimeout);
Append(sb, OptionKeys.User, User);
Append(sb, OptionKeys.Password, (includePassword || string.IsNullOrEmpty(Password)) ? Password : "*****");
Append(sb, OptionKeys.TieBreaker, tieBreaker);
Append(sb, OptionKeys.WriteBuffer, writeBuffer);
......@@ -597,9 +606,10 @@ private static void Append(StringBuilder sb, string prefix, object value)
private void Clear()
{
ClientName = ServiceName = Password = tieBreaker = sslHost = configChannel = null;
ClientName = ServiceName = User =Password = tieBreaker = sslHost = configChannel = null;
keepAlive = syncTimeout = asyncTimeout = connectTimeout = writeBuffer = connectRetry = configCheckSeconds = DefaultDatabase = null;
allowAdmin = abortOnConnectFail = highPrioritySocketThreads = resolveDns = ssl = null;
SslProtocols = null;
defaultVersion = null;
EndPoints.Clear();
commandMap = null;
......@@ -686,6 +696,9 @@ private void DoParse(string configuration, bool ignoreUnknown)
case OptionKeys.Version:
DefaultVersion = OptionKeys.ParseVersion(key, value);
break;
case OptionKeys.User:
User = value;
break;
case OptionKeys.Password:
Password = value;
break;
......
......@@ -753,8 +753,16 @@ private async Task HandshakeAsync(PhysicalConnection connection, LogProxy log)
return;
}
Message msg;
string password = Multiplexer.RawConfig.Password;
if (!string.IsNullOrWhiteSpace(password))
// note that we need "" (not null) for password in the case of 'nopass' logins
string user = Multiplexer.RawConfig.User, password = Multiplexer.RawConfig.Password ?? "";
if (!string.IsNullOrWhiteSpace(user))
{
log?.WriteLine("Authenticating (user/password)");
msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.AUTH, (RedisValue)user, (RedisValue)password);
msg.SetInternalCall();
await WriteDirectOrQueueFireAndForgetAsync(connection, msg, ResultProcessor.DemandOK).ForAwait();
}
else if (!string.IsNullOrWhiteSpace(password))
{
log?.WriteLine("Authenticating (password)");
msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.AUTH, (RedisValue)password);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment