lib/faye/authentication/extension.rb in faye-authentication-0.1.0 vs lib/faye/authentication/extension.rb in faye-authentication-0.2.0
- old
+ new
@@ -1,24 +1,33 @@
+require 'faye'
+
module Faye
module Authentication
class Extension
+ include Faye::Logging
def initialize(secret)
- @secret = secret
+ @secret = secret.to_s
end
def incoming(message, callback)
if message['channel'] == '/meta/subscribe' || !(message['channel'] =~ /^\/meta\/.*/)
- unless Faye::Authentication.valid?({
- 'channel' => message['subscription'] || message['channel'],
- 'clientId' => message['clientId'],
- 'signature' => message['signature']
- }, @secret)
- message['error'] = 'Invalid signature'
+ 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
-
end
end
end