Sha256: ad409a7f4be16f60d79ceebe05edc9e8567f36890b8b3854abea93850bab8346

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require 'faye'

module Faye
  module Authentication
    class ServerExtension
      include Faye::Logging

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

      def incoming(message, callback)
        if Faye::Authentication.authentication_required?(message)
          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.4.0 lib/faye/authentication/server_extension.rb