You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to write a Python client for a pulsar server written with BasicAuth mean custom auth (authenticationMethods=customAuth) that authenticates with userId and password params. I wrote the following code for this, but it did not work.
import pulsar
from pulsar import Authentication
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
class CustomAuthProvider(Authentication):
def __init__(self, username, password):
self.userId = username
self.password = password
self.auth_type = "customAuth"
self.auth = self.get_auth_data()
def get_auth_data(self):
return pulsar.BasicAuthAuthentication(self.userId, self.password)
def auth_method_name(self):
return self.auth_type
class Messenger():
def __init__(self) -> None:
self.pulsar_server_url = "pulsar://192.168.56.1:6650"
self.client = None
self.username = "user"
self.password = "95ce64b2-69a9-3c4e-8e2e-ab244acfdd99"
def connect_to_server(self):
auth_provider = CustomAuthProvider(self.username, self.password)
try:
logging.info("Trying to connect to Pulsar...")
self.client = pulsar.Client(
self.pulsar_server_url,
authentication=auth_provider
)
logging.info("Connected to Pulsar server!")
except Exception as e:
logging.error(f"Failed to connect to Pulsar: {str(e)}")
if self.client:
logging.debug(f"Client object: {self.client}")
if __name__ == '__main__':
app = Messenger()
app.connect_to_server()
Also, the broker conf I made for custom CustomAuthProvider is as follows.
### --- Authentication --- ###
authenticationEnabled=true
# Specify the authentication providers to use
authenticationProviders=com.liderahenkpulsar.auth.BasicAuthProvider
# Define the authentication method name that matches your AuthenticationBasicAuth class
# This should match the value returned by getAuthMethodName()
authenticationMethods=customAuth
# Authentication settings of the broker itself. Used when the broker connects to other brokers,
# either in same or other clusters
brokerClientAuthenticationPlugin=com.liderahenkpulsar.auth.AuthenticationBasicAuth
brokerClientAuthenticationParameters=
Please give support in Python client for sending basic auth credentials while connecting to server with userId and password.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to write a Python client for a pulsar server written with BasicAuth mean custom auth (authenticationMethods=customAuth) that authenticates with userId and password params. I wrote the following code for this, but it did not work.
Also, the broker conf I made for custom CustomAuthProvider is as follows.
Please give support in Python client for sending basic auth credentials while connecting to server with userId and password.
Beta Was this translation helpful? Give feedback.
All reactions