How to get current user from a Django Channels web socket packet?
<p>I was following this tutorial: <a href="https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django" rel="noreferrer">Finally, Real-Time Django Is Here: Get Started with Django Channels</a>.</p>

<p>I wanted to extend the app by using Django User objects instead of the <code>handle</code> variable. <strong>But how can I get the current user from the received WebSocket packet in my <code>ws_recieve(message)</code> function?</strong></p>

<p>I noticed that both the <code>csrftoken</code> and the first ten digits of <code>sessionid</code> from the web socket packet match a normal HTTP request. Can I get the current user with this information?</p>

<p>For reference the received packet looks like this:</p>

<pre><code>{'channel': &lt;channels.channel.Channel object at 0x110ea3a20&gt;,
 'channel_layer': &lt;channels.asgi.ChannelLayerWrapper object at 0x110c399e8&gt;,
 'channel_session': &lt;django.contrib.sessions.backends.db.SessionStore object at 0x110d52cc0&gt;,
 'content': {'client': ['127.0.0.1', 52472],
             'headers': [[b'connection', b'Upgrade'],
                         [b'origin', b'http://0.0.0.0:8000'],
                         [b'cookie',
                          b'csrftoken=EQLI0lx4SGCpyTWTJrT9UTe1mZV5cbNPpevmVu'
                          b'STjySlk9ZJvxzHj9XFsJPgWCWq; sessionid=kgi57butc3'
                          b'zckszpuqphn0egqh22wqaj'],
                         [b'cache-control', b'no-cache'],
                         [b'sec-websocket-version', b'13'],
                         [b'sec-websocket-extensions',
                          b'x-webkit-deflate-frame'],
                         [b'host', b'0.0.0.0:8000'],
                         [b'upgrade', b'websocket'],
                         [b'sec-websocket-key', b'y2Lmb+Ej+lMYN+BVrSXpXQ=='],
                         [b'user-agent',
                          b'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) '
                          b'AppleWebKit/602.1.50 (KHTML, like Gecko) Version'
                          b'/10.0 Safari/602.1.50'],
                         [b'pragma', b'no-cache']],
             'order': 0,
             'path': '/chat-message/',
             'query_string': '',
             'reply_channel': 'websocket.send!UZaOWhupBefN',
             'server': ['127.0.0.1', 8000]},
 'reply_channel': &lt;channels.channel.Channel object at 0x110ea3a90&gt;}
</code></pre>