【发布时间】:2016-03-08 14:34:23
【问题描述】:
我在我的应用程序中使用 ActinCable,但我遇到了授权问题。目前,actioncable 还试图反复授权网站上的每一个人。
这会在我的日志中返回An unauthorized connection attempt was rejected 的恒定流。现在这是因为未登录的访问者也试图获得访问权限。
我的connection.rb 看起来像这样:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
if current_user = User.find_by(id: cookies.signed[:user_id])
current_user
else
reject_unauthorized_connection
end
end
end
end
现在我想知道是否可以让只有登录的人才能尝试获得connnection.rb的授权,而不是每个使用该网站的访问者。我对 ActionCable 太陌生,不知道如何限制这一点 - ActionCable 的文档仍处于早期阶段。
【问题讨论】: