2222static const std::string PARAM_TLS_CERT = " certificatePath" ;
2323static const std::string PARAM_TLS_KEY = " privateKeyPath" ;
2424static const std::string PARAM_TOKEN = " token" ;
25+ static const std::string PARAM_USERNAME = " username" ;
26+ static const std::string PARAM_PASSWORD = " password" ;
2527
2628Napi::FunctionReference Authentication::constructor;
2729
@@ -49,7 +51,7 @@ Authentication::Authentication(const Napi::CallbackInfo &info)
4951
5052 std::string authMethod = info[0 ].ToString ().Utf8Value ();
5153
52- if (authMethod == " tls" || authMethod == " token" ) {
54+ if (authMethod == " tls" || authMethod == " token" || authMethod == " basic " ) {
5355 if (info.Length () < 2 || !info[1 ].IsObject ()) {
5456 Napi::Error::New (env, " Authentication parameter must be a object" ).ThrowAsJavaScriptException ();
5557 return ;
@@ -73,6 +75,15 @@ Authentication::Authentication(const Napi::CallbackInfo &info)
7375 }
7476 this ->cAuthentication =
7577 pulsar_authentication_token_create (obj.Get (PARAM_TOKEN ).ToString ().Utf8Value ().c_str ());
78+ } else if (authMethod == " basic" ) {
79+ if (!obj.Has (PARAM_USERNAME ) || !obj.Get (PARAM_USERNAME ).IsString () || !obj.Has (PARAM_PASSWORD ) ||
80+ !obj.Get (PARAM_PASSWORD ).IsString ()) {
81+ Napi::Error::New (env, " Missing required parameter" ).ThrowAsJavaScriptException ();
82+ return ;
83+ }
84+ this ->cAuthentication =
85+ pulsar_authentication_basic_create (obj.Get (PARAM_USERNAME ).ToString ().Utf8Value ().c_str (),
86+ obj.Get (PARAM_PASSWORD ).ToString ().Utf8Value ().c_str ());
7687 }
7788 } else if (authMethod == " athenz" ) {
7889 if (info.Length () < 2 || !info[1 ].IsString ()) {
0 commit comments