【问题标题】:User authentication in tornado websocket application龙卷风 websocket 应用程序中的用户身份验证
【发布时间】:2011-12-07 09:02:26
【问题描述】:

现在,我提高了我的龙卷风技能,并有一个关于用户身份验证的问题。

我的解决方案是在第一页上创建安全令牌,然后将其与其他数据一起发送,从 javascript 到龙卷风服务器,在那里进行检查和验证用户。

我想到了 cookie,但我不知道如何在 WebSocketHandler.on_message 中读取 cookie

你怎么看?我错在哪里?谢谢

【问题讨论】:

    标签: python authentication tornado


    【解决方案1】:

    我建议你阅读文档中的overview section

    那里应该有一些相关的内容:

    编辑

    我刚刚意识到您的问题是关于 websockets 的。我相信您可以使用您概述的方法:

    • 在应用的非 websocket 部分创建一个 cookie
    • 检查 websocket 处理程序中的 cookie

    您应该能够使用 self.request.headers 访问 websocket 处理程序中的请求标头。

    【讨论】:

    【解决方案2】:

    客户端可能会使用假用户创建请求标头: 'user="ImFkbWxxxx==|xxxxxxxxxx|9d847f58a6897df8912f011f0a784xxxxxxxxxx"'

    我认为以下方法更好。 如果用户不存在或者 cookie id 不正确或伪造,那么函数 get_secure_cookie 将不会返回用户

    class WebSocketHandler(tornado.websocket.WebSocketHandler):
    
        def open(self):
            user_id = self.get_secure_cookie("user")
            if not user_id: return None
            ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-12
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      相关资源
      最近更新 更多