Sha256: 1a2ac3d45abd9d978fc1cffddef993badf14c5e7021568ef05874243d41cc1e1

Contents?: true

Size: 943 Bytes

Versions: 5

Compression:

Stored size: 943 Bytes

Contents

require 'base64'

module Yoti
  # Converts a basic Net::HTTP request into a Yoti Signed Request
  class SignedRequest
    def initialize(unsigned_request, path, payload = {})
      @http_req = unsigned_request
      @path = path
      @payload = payload
      @auth_key = Yoti::SSL.auth_key_from_pem
    end

    def sign
      @http_req['X-Yoti-Auth-Digest'] = message_signature
      @http_req['X-Yoti-SDK'] = Yoti.configuration.sdk_identifier
      @http_req['X-Yoti-SDK-Version'] = "#{Yoti.configuration.sdk_identifier}-#{Yoti::VERSION}"
      @http_req
    end

    private

    def message_signature
      @message_signature ||= Yoti::SSL.get_secure_signature("#{http_method}&#{@path}#{payload_string}")
    end

    def http_method
      @http_req.method
    end

    # Create the base64 encoded request body
    def payload_string
      return '' unless @payload

      '&' + Base64.strict_encode64(@payload.to_json)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yoti-1.6.4 lib/yoti/http/signed_request.rb
yoti-1.6.3 lib/yoti/http/signed_request.rb
yoti-1.6.2 lib/yoti/http/signed_request.rb
yoti-1.6.1 lib/yoti/http/signed_request.rb
yoti-1.6.0 lib/yoti/http/signed_request.rb