Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:48:05+00:00 2026-06-15T18:48:05+00:00

Once a message is sent through a Socket.IO connection from client (JS) to server

  • 0

Once a message is sent through a Socket.IO connection from client (JS) to server (django/python) using django-socketio, is it possible to figure out which user was authenticated when the page was rendered?

In this case the view is being served up by django and it requires authentication — normally on the server I would be able to do user = request.user, but in the events.py file the request.user just returns an AnonymousUser object. This makes sense because the websocket server is an entirely separate process than the django web server, and thus the user has not authenticated on that socket connection.

I’m thinking I’ll have to come up with some clever code to embed the user ID into the message that is being sent to the server, and in that case I would need to add some handshaking to ensure that the end user cannot spoof it.

Has anyone come up with a clever solution to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:48:06+00:00Added an answer on June 15, 2026 at 6:48 pm

    Found my own solution to this issue. The trick is to add the session_key from the django request object into the django-socketio message before you send it up to the server; then back on the server-side you can resolve the session_key back to a User object. Here is the code:

    Template file: (served up by django server)

    <input type="hidden" id="session_key" value="{{ request.session.session_key }}">
    ...
    <script type="text/javascript" charset="utf-8">
        function someHandler(action, post_id, some_val){
            var data = {
                'action': action,
                'post_id': post_id,
                'value': some_val,
                'session_key': $("#session_key").val()
            };
            socket.send(data);
        }
    </script>
    

    events.py: (processed by django-socketio server)

    from django.contrib.sessions.models import Session
    from django.contrib.auth.models import User
    
    def message(request, socket, context, message):
        session = Session.objects.get(session_key=message['session_key'])
        uid = session.get_decoded().get('_auth_user_id')
        user = User.objects.get(pk=uid)
    

    Profit!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of writing a TCP server using Berkely SOCKET API
It appears the true From tag of a message sent from an email service
I want to add a custom message once someone saves a specific content-type telling
Once in a while i get the error message Bitmap size exceeds VM budget.
Once the system is shutdown there will be message in syslog file. I have
Once a push notification is sent to a device via APNS, what are normal
I'm having a strange problem while attempting to transform a blocking socket server into
I have a bytearray consisting of data received from a WebSocket-client. The data I
I am using MVVM Light toolkit Messenger class- A Messenger class (and diverse message
I am writing a program in VB.Net to manage text messages sent through an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.