【问题标题】:Only connect users to ActionCable仅将用户连接到 ActionCable
【发布时间】: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 的文档仍处于早期阶段。

【问题讨论】:

    标签: ruby-on-rails actioncable


    【解决方案1】:

    连接尝试是在调用ActionCable.createConsumer() 时进行的。您应该尝试仅在用户登录时调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-10
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 2016-11-09
      • 2019-10-23
      • 2017-11-17
      相关资源
      最近更新 更多