Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Crossbar/Autobahn进行用户通知的身份验证?_Python_Authentication_Autobahn_Crossbar_Wamp Protocol - Fatal编程技术网

Python 使用Crossbar/Autobahn进行用户通知的身份验证?

Python 使用Crossbar/Autobahn进行用户通知的身份验证?,python,authentication,autobahn,crossbar,wamp-protocol,Python,Authentication,Autobahn,Crossbar,Wamp Protocol,我目前正试图通过纵横杆/高速公路使用Websockets实现一个用户通知系统。我已经做了多个测试并浏览了文档,但是,我不确定是否有解决方案可以让以下工作流工作: 用户使用web应用程序登录--这是通过JWT完成的 前端建立到正在运行的crossbar实例的websocket连接 前端尝试订阅专门用于用户通知的URI:即com.example.notifications.user.23或com.example.user.23.notifications”。其中23`是用户id 检查用户的JWT以查

我目前正试图通过纵横杆/高速公路使用Websockets实现一个用户通知系统。我已经做了多个测试并浏览了文档,但是,我不确定是否有解决方案可以让以下工作流工作:

  • 用户使用web应用程序登录--这是通过JWT完成的
  • 前端建立到正在运行的
    crossbar
    实例的websocket连接
  • 前端尝试订阅专门用于用户通知的URI:即
    com.example.notifications.user.23
    com.example.user.23.notifications”。其中
    23`是用户id
  • 检查用户的JWT以查看是否允许用户访问订阅
  • 当生成活动并引发通知时,后端将发布用户特定的URI
  • 对于步骤3,我无法判断当前的support auth方法是否满足我的需要。理想情况下,我想要一个auth方法,我可以自定义它(以便在Crossbar中实现JWT验证器),它可以应用于URI模式,但不允许订阅用户访问整个模式。动态身份验证方法部分解决了这一问题,但缺少后半部分:

    例如(我的理想工作流):

  • 用户尝试订阅URI
    com.example.User.23.notifications
  • URI匹配
    com.example.user..notifications
    (中的通配符模式)
  • 验证身份验证令牌,并且用户只能访问
    com.example.user.23.notifications
    上述目标是否可以通过简单的方式实现?据我所知,只有以某种方式生成一个
    .crossbar/config.json
    ,其中包含所有用户ID的URI排列,并为每个新用户自动生成一个新配置,这才可能实现这一点——这完全不是一个合理的解决方案

    感谢您的帮助

    使用授权人

    为加入/验证时分配的会话的用户角色注册动态授权人:

               {
                  "name": "authorizer",
                  "permissions": [
                    {
                      "uri": "com.example.authorize",
                      "register": true
                    }
                  ]
                },
                {
                  "name": "authenticator",
                  "permissions": [
                    {
                      "uri": "com.example.authenticate",
                      "register": true
                    }
                  ]
                },
                {
                  "name": "user",
                  "authorizer": "com.example.authorize"
                },
    ...
    "components": [
        {
          "type": "class",
          "classname": "example.AuthenticatorSession",
          "realm": "realm1",
          "role": "authenticator",
          "extra": {
            "backend_base_url": "http://localhost:8080/ws"
          }
        },
        {
          "type": "class",
          "classname": "example.AuthorizerSession",
          "realm": "realm1",
          "role": "authorizer"
        }
      ]
    
    写一节课

    class AuthorizerSession(ApplicationSession):
        @inlineCallbacks
        def onJoin(self, details):
            print("In AuthorizerSession.onJoin({})".format(details))
            try:
                yield self.register(self.authorize, 'com.example.authorize')
                print("AuthorizerSession: authorizer registered")
            except Exception as e:
                print("AuthorizerSession: failed to register authorizer procedure ({})".format(e))
    
        def authorize(self, session, uri, action):
            print("AuthorizerSession.authorize({}, {}, {})".format(session, uri, action))
            if session['authrole'] == u'backend':  # backnend can do whatever
                return True
            [Authorization logic here]
            return authorized
    

    确实如此。我以前确实尝试过,但我没有意识到在多个事件中都会调用它。在
    会话
    uri
    操作
    中提供的数据也不足以满足我的需要,因此我已将uri数据传递到
    授权