I have RoR 5.0.0.1 project with ActionCable functionality. We have staging environmen with http authentification. I need ActionCable to work with our staging. What I need to do to get work ActionCable and http auth in our project? My current connection.rb file:
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
if verified_user = env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end
end
end
My staging.rb file:
config.action_cable.url = "ws://user:password@staging.domain.io/cable"
config.action_cable.allowed_request_origins = ['http://user:password@staging.domain.io', 'http://staging.domain.io']
config.middleware.use '::Rack::Auth::Basic' do |u, p|
[u, p] == ['user', 'password']
end
Logs:
2017-11-10T08:15:27.174024+00:00 app[web.1]: [ActionCable] [dev_monkey2@domain.io] TestStatusChannel is streaming from test_status:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvTW9ua2V5LzIw:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvRXhwZXJpbWVudC8zM
2017-11-10T08:15:26.985632+00:00 app[web.1]: [ActionCable] [dev_monkey2@domain.io] Registered connection (Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvTW9ua2V5LzIw)
2017-11-10T08:15:27.173731+00:00 app[web.1]: [ActionCable] [dev_monkey2@domain.io] TestStatusChannel is transmitting the subscription confirmation
2017-11-10T08:19:39.432364+00:00 app[web.1]: [ActionCable] [dev_monkey2@domain.io] Finished "/cable/" [WebSocket] for 90.64.96.233 at 2017-11-10 08:19:39 +0000
2017-11-10T08:19:39.432569+00:00 app[web.1]: [ActionCable] [dev_monkey2@domain.io] TestStatusChannel stopped streaming from test_status:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvTW9ua2V5LzIw:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvRXhwZXJpbWVudC8zM
2017-11-10T08:46:46.955323+00:00 app[web.1]: [ActionCable] Broadcasting to test_status:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvTW9ua2V5LzIw:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvRXhwZXJpbWVudC8zM: 182
2017-11-10T08:46:48.156125+00:00 app[web.1]: [ActionCable] Broadcasting to upload_progress:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvTW9ua2V5LzIw:Z2lkOi8vc2ltcGxlY29kZWNhc3RzLXNhYXMvRXhwZXJpbWVudC8zM: {:event=>"publish"}
Thanks.