Class: Faye::Authentication::ServerExtension

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/faye/authentication/server_extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret, options = {}) ⇒ ServerExtension

Returns a new instance of ServerExtension.



8
9
10
11
# File 'lib/faye/authentication/server_extension.rb', line 8

def initialize(secret, options = {})
  @options = options
  @secret = secret.to_s
end

Instance Method Details

#incoming(message, callback) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/faye/authentication/server_extension.rb', line 13

def incoming(message, callback)
  if Faye::Authentication.authentication_required?(message, @options)
    begin
      Faye::Authentication.validate(message['signature'],
                                    message['subscription'] || message['channel'],
                                    message['clientId'],
                                    @secret)
      debug("Authentication sucessful")
    rescue AuthError => exception
      message['error'] = case exception
        when ExpiredError then 'Expired signature'
        when PayloadError then 'Required argument not signed'
        else 'Invalid signature'
        end
      debug("Authentication failed: #{message['error']}")
    end
  end
  callback.call(message)
end