Sha256: c25bcb24c866025bd5cd8d97de4530ea1530fcdf19628c3233304b2f780c4c75

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

require 'faye'

module Faye
  module Authentication
    class ServerExtension
      include Faye::Logging

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

      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
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
faye-authentication-1.9.1 lib/faye/authentication/server_extension.rb
faye-authentication-1.9.0 lib/faye/authentication/server_extension.rb
faye-authentication-1.8.2 lib/faye/authentication/server_extension.rb
faye-authentication-1.8.1 lib/faye/authentication/server_extension.rb
faye-authentication-1.8.0 lib/faye/authentication/server_extension.rb
faye-authentication-1.7.0 lib/faye/authentication/server_extension.rb
faye-authentication-1.6.1 lib/faye/authentication/server_extension.rb
faye-authentication-1.6.0 lib/faye/authentication/server_extension.rb