This is an automated email from the ASF dual-hosted git repository.
blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 25214f8 Add Basic Authentication support to AuthenticationFactory
(#286)
25214f8 is described below
commit 25214f89f1d94bf8dc4931fbab07c0fb144bbeed
Author: Ethan Brown <[email protected]>
AuthorDate: Wed Mar 18 02:20:14 2026 -0500
Add Basic Authentication support to AuthenticationFactory (#286)
Introduced BasicAuthentication class implementing IAuthentication.
Supports authentication via userId/password or token supplier.
Added two factory methods for BasicAuthentication creation.
Credentials are encoded as UTF-8 bytes with method name "basic".
---
src/DotPulsar/AuthenticationFactory.cs | 10 ++++++++
src/DotPulsar/Internal/BasicAuthentication.cs | 37 +++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/src/DotPulsar/AuthenticationFactory.cs
b/src/DotPulsar/AuthenticationFactory.cs
index 8870b98..89f3a3e 100644
--- a/src/DotPulsar/AuthenticationFactory.cs
+++ b/src/DotPulsar/AuthenticationFactory.cs
@@ -31,4 +31,14 @@ public static class AuthenticationFactory
/// Create an authentication provider for token based authentication.
/// </summary>
public static IAuthentication Token(Func<CancellationToken,
ValueTask<string>> tokenSupplier) => new TokenAuthentication(tokenSupplier);
+
+ /// <summary>
+ /// Create an authentication provider for basic authentication.
+ /// </summary>
+ public static IAuthentication Basic(string userId, string password) => new
BasicAuthentication(userId, password);
+
+ /// <summary>
+ /// Create an authentication provider for basic authentication.
+ /// </summary>
+ public static IAuthentication Basic(Func<CancellationToken,
ValueTask<string>> tokenSupplier) => new BasicAuthentication(tokenSupplier);
}
diff --git a/src/DotPulsar/Internal/BasicAuthentication.cs
b/src/DotPulsar/Internal/BasicAuthentication.cs
new file mode 100644
index 0000000..462d27c
--- /dev/null
+++ b/src/DotPulsar/Internal/BasicAuthentication.cs
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace DotPulsar.Internal;
+
+using DotPulsar.Abstractions;
+
+public sealed class BasicAuthentication : IAuthentication
+{
+ private readonly Func<CancellationToken, ValueTask<string>> _tokenSupplier;
+
+ public BasicAuthentication(string userId, string password)
+ {
+ _tokenSupplier = (cancellationToken) => new
ValueTask<string>($"{userId}:{password}");
+ }
+
+ public BasicAuthentication(Func<CancellationToken, ValueTask<string>>
tokenSupplier) => _tokenSupplier = tokenSupplier;
+
+ public string AuthenticationMethodName => "basic";
+
+ public async ValueTask<byte[]> GetAuthenticationData(CancellationToken
cancellationToken)
+ {
+ var token = await
_tokenSupplier(cancellationToken).ConfigureAwait(false);
+ return System.Text.Encoding.UTF8.GetBytes(token);
+ }
+}