-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lack of user-authentication methods? #193
Comments
@benjamin-tang-pusher @samuelyallop-pusher @benw-pusher |
I'll raise this internally, this may have been an oversight. |
@benw-pusher |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you. |
I created a PR with some "user" functions: |
@benw-pusher do I need to do anything else regarding the opened PR? Thx |
@benjamin-tang-pusher @samuelyallop-pusher @benw-pusher any news about the opened PR? Thanks so far. |
Hey, I will test your PR and see if its good enough to be merged. |
was this merged? |
Not yet. I'm waiting too. |
🦗 🦗 edit: Since this library seems a bit outdated, and Pusher documentation is not enough clear, I did this based on the work of @andersonrocha0 in #207 I did this to use it with DRF. You need to call hope it helps someone import json
from django.conf import settings
from pusher import sign
from rest_framework import status
from rest_framework.response import Response
def generate_pusher_response(socket_id, prefix, user_data_encoded=None):
response = {
'auth': generate_auth_string(socket_id, prefix, user_data_encoded),
}
if user_data_encoded:
response['user_data'] = user_data_encoded
return response
def generate_auth_string(socket_id, prefix, user_data_encoded=None):
string_to_sign = f'{socket_id}{prefix}{user_data_encoded or ""}'
signature = sign(settings.PUSHER_APP_SECRET, string_to_sign)
return f"{settings.PUSHER_APP_KEY}:{signature}"
class PusherAuthentication(APIView):
def post(self, request, *args, **kwargs):
socket_id = request.data.get('socket_id')
response_data = {}
response_status = status.HTTP_403_FORBIDDEN
try:
user_data = {'id': str(request.user.id)}
user_data_encoded = json.dumps(user_data)
response_data = generate_pusher_response(socket_id, '::user::', user_data_encoded)
response_status = status.HTTP_200_OK
except Exception as e: # noqa
pass
return Response(response_data, status=response_status)
class PusherChannelAuthorization(APIView):
def post(self, request, *args, **kwargs):
socket_id = request.data.get('socket_id')
channel = request.data.get('channel_name')
room_id = channel.removeprefix('private-channel-')
response_data = {}
response_status = status.HTTP_403_FORBIDDEN
if request.user.rooms.filter(id=room_id).exists():
try:
response_data = generate_pusher_response(socket_id, f':{channel}')
response_status = status.HTTP_200_OK
except Exception as e: # noqa
pass
return Response(response_data, status=response_status) |
Bump |
Is the lack of user authentication intentional for this library? Seems like the preferred method is now to use signin() method which would cause a POST to the user-auth endpoint (compared with just joining a private channel).
The text was updated successfully, but these errors were encountered: