Sha256: 67ebcd6f3a5b2a5b8480fa1bd1128581b12c06ae193708b4e109484490c9052e

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'faye'

module Faye
  module Authentication
    class Extension
      include Faye::Logging

      def initialize(secret)
        @secret = secret.to_s
      end

      def incoming(message, callback)
        if message['channel'] == '/meta/subscribe' || !(message['channel'] =~ /^\/meta\/.*/)
          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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faye-authentication-0.2.0 lib/faye/authentication/extension.rb