pusher / pusher-http-python

Pusher Channels HTTP API library for Python
https://pusher.com/docs/server_api_guide
MIT License
375 stars 112 forks source link

Add user authentication and the possibility to trigger/send a message… #207

Open andersonrocha0 opened 1 year ago

andersonrocha0 commented 1 year ago

What does this PR do?

Add the authenticate_user method allowing clients to authenticate users. Add the send_to_user_method allowing any backend to send messages to a specific user.

CHANGELOG

benjamin-tang-pusher commented 1 year ago

When I call channels_client.send_to_user("123", "user-event", {"message": "hello worlds"}) I get this error (although the message goes through to my client)

File "/Users/benjamintang/development/python/channels/app.py", line 124, in send_to_user
channels_client.send_to_user("123", "user-event", {"message": "hello worlds"})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/benjamintang/development/python/channels/venv/lib/python3.11/site-packages/pusher/pusher.py", line 151, in send_to_user
return self._pusher_client.send_to_user(user_id, event_name, data)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/benjamintang/development/python/channels/venv/lib/python3.11/site-packages/pusher/http.py", line 31, in __call__
return self.client.http.send_request(self.make_request(*args, **kwargs))
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/benjamintang/development/python/channels/venv/lib/python3.11/site-packages/pusher/requests.py", line 39, in send_request
        self.session = requests.Session()

    def send_request(self, request):
        resp = self.session.request(
            request.method,
            ^^^^^^^^^^^^^^
            request.url,
            headers=request.headers,
            data=request.body,
            timeout=self.client.timeout,
            **self.options)
AttributeError: 'dict' object has no attribute 'method'

Do you not get this too? It's odd, as the trigger() method should put POST as the argument, so I'm not sure where its going missing.

@andersonrocha0

andersonrocha0 commented 1 year ago

@benjamin-tang-pusher Yes, you are right.

I found the problem and fixed it.

The @request_method is unnecessary because the send_to_user is only a wrapper calling the trigger.

Now, the code is fixed and working.

Please let me know if you have any other problems.

:)

benjamin-tang-pusher commented 1 year ago

Whoops, I forgot about that decorator. I gave it another test and it works now.

I will ask the team to review it.

andersonrocha0 commented 1 year ago

@fbenevides do you have any news?

Thx.

amplicity commented 11 months ago

+1, need this

andersonrocha0 commented 7 months ago

Any news here?

alexanderlukens commented 4 months ago

@fbenevides any updates on this PR? Would be super helpful to have 😄

andersonrocha0 commented 4 weeks ago

@amad @robertoles @benjamin-tang-pusher @benw-pusher I'm tagging you because you were the last committers on this project. Do you have any intention to finish this PR?

Thanks for any help you can give me.

:)