Authentication with sockjs-tornado

314 views
Skip to first unread message

zev-g...@strangersgate.com

unread,
Sep 30, 2013, 11:54:07 AM9/30/13
to soc...@googlegroups.com
Hi,
I want to do an authentication step on the server when the connection is established but I've run into a few problems.

The documentation for SockJSConnection.on_open states "If you return False, connection will be rejected.  You can also throw Tornado HTTPError to close connection."  However, a quick look at the call site in session.py:110 shows that at least the first part isn't true and empirically the second half does not seem true, either.

    def verify_state(self):
        """Verify if session was not yet opened. If it is, open it and call connections `on_open`"""
        if self.state == CONNECTING:
            self.state = OPEN

            self.conn.on_open(self.conn_info)

When I found that the above approach didn't work, I tried sending a message to the client to inform it of the authentication error and then closing the connection in on_open.  The problem is that for some transports the message will never get sent because the message will be queued (because handler.active is set to False in handler.send_pack() before SockJSConnection.on_open() is called) and the queue is not flushed on close.

Is there a better way to handle authentication before the connection is set up besides doing a full authentication handshake?


Thanks,
Zev

zev-g...@strangersgate.com

unread,
Oct 2, 2013, 1:27:58 PM10/2/13
to soc...@googlegroups.com, zev-g...@strangersgate.com
Ah, I missed the FAQ question: https://sockjs-tornado.readthedocs.org/en/latest/faq.html#how-do-i-implement-authentication-in-my-application

The documentation should probably be updated, though.


Zev

Serge S. Koval

unread,
Oct 2, 2013, 1:44:38 PM10/2/13
to Zev Benjamin, sockjs
And there's related bug which might prevent from receiving last message when connection is closed and client is connected with one of the polling transports: https://github.com/mrjoes/sockjs-tornado/issues/44

I hope to fix it, but currently overloaded with side projects.

Serge.


--
You received this message because you are subscribed to the Google Groups "sockjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sockjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages