0

I run a django server and am trying to create a channel for chatting. The client is a react-native application, with javascript backend. When the user connects to the server via websocket (or afterwards with a message, whatever is better), I want to be able to perform an authentication check, to see if the user is already in the database and get who this user is.

I use default django auth accounts (django.contrib.auth.models). For authenticating the http requests I use django.contrib.auth.decorators.login_required and from the client I send an Authorization Header with the JWT token.

How should I do the same for websocket requests? The recommended chat consumer uses channels.auth.channel_session_user_from_http. Is this the correct way for what I want? And how can I send the user's credentials (or token) from the client so that the server can check them?

I saw a relevant SO question and the relevant documentation, but could not solve my problem. Any help would be appreciated.

django version: 1.11.20
django-channels version: 1.1.8

Thanasis1101
  • 1,614
  • 4
  • 17
  • 28
  • So why did these two documents not solve your problem? What have you tried and what isn't working exactly? – dirkgroten Apr 09 '19 at 11:01
  • @dirkgroten The documentation shows the server side but the client is the browser and the login is performed with forms (I want to do it with websocket requests). For the relevant SO question I want to know if passing the username and password or token (as suggested [here](https://stackoverflow.com/a/41521871/7053344)) is the commonly used (secure) solution for my current client-server structure (django with javascript), and if it isn't, then what should I use. – Thanasis1101 Apr 09 '19 at 11:21

0 Answers0