2

My website hosts a lot of APIs(CRUDs) using DJR. I am using DJR Token based authentication and for testing I would add this header to postman

Key : Authorization 
value : Token 826fdf3067b07afdf9edd89a6c9facd9920de8b8

and Django Rest Framework would easily be able to authenticate the user. Now I inlcuded Django channels constantly 1.1.5 and wanted to know how I could do token based authentication. I read this post and it suggests that I copy this mixin to the project. I just started with Django-channels and am not sure how to include that mixin to my code. Currently I have something like this

@channel_session_user_from_http
def ws_connect(message):
    user = message.user
    message.reply_channel.send({"accept": True}) #Send back Acceptance response. 

@channel_session_user
def chat_join(message):
    user = message.user #Get authenticated user

I have the following two questions

1-How do I include that mixin in my current project ? I know you include mixins in classes using class classname(SomeMixin). How would I go about including this mixin into my code ?

2-Will I need to include an authentication token in my json message that I send to the websocket ?

Any suggestions would be great. `

MistyD
  • 16,373
  • 40
  • 138
  • 240

0 Answers0