pusher-http-python icon indicating copy to clipboard operation
pusher-http-python copied to clipboard

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

Open andersonrocha0 opened this issue 2 years ago • 8 comments
trafficstars

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.

  • [x] If you have changed dependencies, ensure both requirements.txt and setup.py have been updated

CHANGELOG

  • [ADDED] authenticate_user method
  • [ADDED] send_to_user method

andersonrocha0 avatar Jun 14 '23 13:06 andersonrocha0

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

benjamin-tang-pusher avatar Aug 15 '23 21:08 benjamin-tang-pusher

@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.

:)

andersonrocha0 avatar Aug 17 '23 15:08 andersonrocha0

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

I will ask the team to review it.

benjamin-tang-pusher avatar Aug 18 '23 14:08 benjamin-tang-pusher

@fbenevides do you have any news?

Thx.

andersonrocha0 avatar Sep 06 '23 09:09 andersonrocha0

+1, need this

amplicity avatar Oct 11 '23 19:10 amplicity

Any news here?

andersonrocha0 avatar Feb 04 '24 21:02 andersonrocha0