feat: execute full-repo remaining parity closure plan
This commit is contained in:
27
src/NATS.Server/Auth/ProxyAuthenticator.cs
Normal file
27
src/NATS.Server/Auth/ProxyAuthenticator.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace NATS.Server.Auth;
|
||||
|
||||
public sealed class ProxyAuthenticator(ProxyAuthOptions options) : IAuthenticator
|
||||
{
|
||||
public AuthResult? Authenticate(ClientAuthContext context)
|
||||
{
|
||||
if (!options.Enabled)
|
||||
return null;
|
||||
|
||||
var username = context.Opts.Username;
|
||||
if (string.IsNullOrEmpty(username))
|
||||
return null;
|
||||
|
||||
if (!username.StartsWith(options.UsernamePrefix, StringComparison.Ordinal))
|
||||
return null;
|
||||
|
||||
var identity = username[options.UsernamePrefix.Length..];
|
||||
if (identity.Length == 0)
|
||||
return null;
|
||||
|
||||
return new AuthResult
|
||||
{
|
||||
Identity = identity,
|
||||
AccountName = options.Account,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user