Sha256: bcad7a901d8bac1cb2308e5f9a0e239b513a5f2e2b9161ada6520e495f18f7fe

Contents?: true

Size: 509 Bytes

Versions: 6

Compression:

Stored size: 509 Bytes

Contents

module Whiplash
  class App
    module Signing
      def signature(body)
        sha256 = OpenSSL::Digest::SHA256.new
        OpenSSL::HMAC.hexdigest(sha256,
          ENV["WHIPLASH_CLIENT_SECRET"], request_body(body))
      end

      def verified?(request)
        body = request.try(:body).try(:read)
        request.headers["X-WHIPLASH-SIGNATURE"] == signature(body)
      end

      private

      def request_body(body)
        body.blank? ? ENV["WHIPLASH_CLIENT_ID"] : body
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
whiplash-app-0.6.2 lib/whiplash/app/signing.rb
whiplash-app-0.6.1 lib/whiplash/app/signing.rb
whiplash-app-0.6.0 lib/whiplash/app/signing.rb
whiplash-app-0.5.1 lib/whiplash/app/signing.rb
whiplash-app-0.5.0 lib/whiplash/app/signing.rb
whiplash-app-0.4.0 lib/whiplash/app/signing.rb