【发布时间】:2023-01-12 19:33:13
【问题描述】:
我正在处理 ActionCable 并在我的 Rails 应用程序中实现了 Doorkeeper 授权。
我想用Doorkeeper::AccessToken和ActionCable实现我的客户authenticate
这是我现在的身份验证方式:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
identified_by :room_id
def connect
self.current_user = find_verified_user
self.room_id = @user.ac_channel_room
end
def disconnect
# When user will disconnect action cable, this method call will be executed.
end
private
def find_verified_user
check_access_token
@user = User.find_by_id(@resource_owner_id) if @resource_owner_id
reject_unauthorized_connection unless @user
end
def check_access_token
# Check provided token is valid or not
params = request.query_parameters
@access_token ||= Doorkeeper::AccessToken.by_token(params[:access_token])
@resource_owner_id = @access_token&.resource_owner_id
end
end
end
问题是这也允许有经验的访问令牌。
请帮忙!
【问题讨论】:
标签: ruby-on-rails actioncable doorkeeper