mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Basic authentication helpers
This commit is contained in:
parent
81bbf9ecba
commit
049cd824c0
3 changed files with 18 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
module ActionCable
|
module ActionCable
|
||||||
module Connection
|
module Connection
|
||||||
|
autoload :Authorization, 'action_cable/connection/authorization'
|
||||||
autoload :Base, 'action_cable/connection/base'
|
autoload :Base, 'action_cable/connection/base'
|
||||||
autoload :Heartbeat, 'action_cable/connection/heartbeat'
|
autoload :Heartbeat, 'action_cable/connection/heartbeat'
|
||||||
autoload :Identification, 'action_cable/connection/identification'
|
autoload :Identification, 'action_cable/connection/identification'
|
||||||
|
|
13
lib/action_cable/connection/authorization.rb
Normal file
13
lib/action_cable/connection/authorization.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module ActionCable
|
||||||
|
module Connection
|
||||||
|
module Authorization
|
||||||
|
class UnauthorizedError < StandardError; end
|
||||||
|
|
||||||
|
private
|
||||||
|
def reject_unauthorized_connection
|
||||||
|
logger.error "An unauthorized connection attempt was rejected"
|
||||||
|
raise UnauthorizedError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,6 +3,7 @@ module ActionCable
|
||||||
class Base
|
class Base
|
||||||
include Identification
|
include Identification
|
||||||
include InternalChannel
|
include InternalChannel
|
||||||
|
include Authorization
|
||||||
|
|
||||||
attr_reader :server, :env
|
attr_reader :server, :env
|
||||||
delegate :worker_pool, :pubsub, to: :server
|
delegate :worker_pool, :pubsub, to: :server
|
||||||
|
@ -85,6 +86,9 @@ module ActionCable
|
||||||
heartbeat.start
|
heartbeat.start
|
||||||
|
|
||||||
message_buffer.process!
|
message_buffer.process!
|
||||||
|
rescue ActionCable::Connection::Authorization::UnauthorizedError
|
||||||
|
respond_to_invalid_request
|
||||||
|
close
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_message(message)
|
def on_message(message)
|
||||||
|
|
Loading…
Reference in a new issue