gwa*_*ton 6 cookies ruby-on-rails heroku session-cookies
我甚至不确定这是正确的问题.
我设置ActionCable来打开一个websocket连接,它在heroku上工作得很好,如果它只是app-name.herokuapp.com但是当我尝试使用为应用程序设置的自定义域时,连接未经验证.
所以,我正在尝试在客户端上设置cookie,以便能够验证用户
通道/ application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.email
end
protected
def find_verified_user # this checks whether a user is authenticated with devise
if cookies.signed['user.id']
verified_user = User.find_by(id: cookies.signed['user.id'])
verified_user
else
reject_unauthorized_connection
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
在example.com上 - 它继续作为未经授权的连接回来.但app-name.herokuapp.com连接正常.
初始化/ warden_hooks.rb
Warden::Manager.after_set_user do |user,auth,opts|
scope = opts[:scope]
auth.cookies.signed["#{scope}.id"] = user.id
end
Run Code Online (Sandbox Code Playgroud)
我尝试允许来自herokuapp.com和example.com的调用:environments/production.rb
Rails.application.configure do
config.action_cable.url = 'wss://app-name.herokuapp.com//cable'
config.action_cable.allowed_request_origins = [ 'https://www.example.com', /http:\/\/www.example.com.*/, 'https://app-name.herokuapp.com', /http:\/\/app-name.herokuapp.com.*/ ]
end
Run Code Online (Sandbox Code Playgroud)
为什么在自定义域上未经验证?如何设置cookie变量来验证它?我对这个概念有什么误解?
谢谢!
PS.Before有人试图添加为"答案" - 是的我将这个帖子的名称更改为example.com和app-name.herokuapp.com,不,它实际上并没有在我的代码中说:)
| 归档时间: |
|
| 查看次数: |
311 次 |
| 最近记录: |