Python 使用Crossbar/Autobahn进行用户通知的身份验证?
我目前正试图通过纵横杆/高速公路使用Websockets实现一个用户通知系统。我已经做了多个测试并浏览了文档,但是,我不确定是否有解决方案可以让以下工作流工作: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以查
crossbar
实例的websocket连接李>
com.example.notifications.user.23
或com.example.user.23.notifications”。其中
23`是用户idcom.example.User.23.notifications
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数据传递到授权
。