1
0
Fork 0
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:
David Heinemeier Hansson 2015-07-07 22:27:44 +02:00
parent 81bbf9ecba
commit 049cd824c0
3 changed files with 18 additions and 0 deletions

View file

@ -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'

View 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

View file

@ -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)