我在服务器端使用带扭曲(wamp)的高速公路和浏览器中的高速公路。是否有一种直接的方法允许/限制每个会话的订阅?例如,客户机不应该订阅与其他用户相关的主题。在
当我不使用横杆io,我尝试使用本页末尾的“Example”部分中显示的Python代码,http://crossbar.io/docs/Authorization/首先使用RPC调用向客户机授予授权。当然,我使用我自己的授权逻辑。一旦此授权成功,我将授予客户端特权,以订阅仅与此客户端相关的主题,如'com.example.user用户名'. 但是,我的问题是,即使auth通过,我也没有找到一种方法来限制ApplicationSession类中的订阅请求,而ApplicationSession类是进行授权的地方。我如何防止授权给user_id=user_a的客户订阅'com.example.user\b'? 在
您可以通过创建自己的路由器进行授权。为此,子类Router()并重写(至少)authorize()方法:
这个方法非常简单,如果返回True,则会话被授权执行它正在尝试的任何操作。您可以制定一个规则,所有订阅都必须以'com.example.USER用户名,因此,python代码将拆分uri,获取第三个字段,并将其与当前会话id进行比较,如果匹配则返回True,否则返回false。这就是事情变得有点奇怪的地方。我有一个类似的代码,下面是我的authorize()方法:
^{pr2}$请注意,我深入到会话中获取_authid,这是一种恶报(我认为),因为我不应该查看这些私有变量。不过,我不知道还能从哪儿弄到。在
另外,值得注意的是,这与身份验证密切相关。在我的实现中,authid是经过身份验证的用户id,它类似于unix用户id(正唯一整数)。我很确定这可以是任何东西,比如一个字符串,所以如果你愿意的话,你应该可以把你的'user'b'作为身份验证id。在
-克
我发现了一个使用Node-guest的相对简单的解决方案。代码如下:
相关问题 更多 >
编程相关推荐