Sha256: 2a3e9b71e3ba2906515bb40c95c42e33c786c9782d57a29095c4c9e6ea666fd3

Contents?: true

Size: 603 Bytes

Versions: 2

Compression:

Stored size: 603 Bytes

Contents

module CrystalApi
  class MessageVerifier
    include HmacRequestSigning

    attr_reader :shared_secret, :request

    def initialize(shared_secret, request)
      @shared_secret = shared_secret
      @request = request
    end

    def verified?
      request_signature(request) == expected_signature
    end

    def expected_signature
      rack_request = Rack::Request.new(request.env)

      sign_params(rack_request.request_method,
                  rack_request.host,
                  rack_request.path,
                  shared_secret,
                  rack_request.params)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crystal_api-0.1.0 lib/crystal_api/message_verifier.rb
crystal_api-0.0.1 lib/crystal_api/message_verifier.rb