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