Module: MAuth::Signed

Included in:
Faraday::Response, Rack::Request
Defined in:
lib/mauth/request_and_response.rb

Overview

methods for an incoming object which is expected to have a signature.

includer must provide

  • #mcc_authentication which returns that header’s value

  • #mcc_time

OR

  • #x_mws_authentication which returns that header’s value

  • #x_mws_time

Instance Method Summary collapse

Instance Method Details

#protocol_versionObject



149
150
151
152
153
154
155
# File 'lib/mauth/request_and_response.rb', line 149

def protocol_version
  if !mcc_authentication.to_s.strip.empty?
    2
  elsif !x_mws_authentication.to_s.strip.empty?
    1
  end
end

#signatureObject



145
146
147
# File 'lib/mauth/request_and_response.rb', line 145

def signature
  signature_info[:signature]
end

#signature_app_uuidObject



137
138
139
# File 'lib/mauth/request_and_response.rb', line 137

def signature_app_uuid
  signature_info[:app_uuid]
end

#signature_infoObject

mauth_client will authenticate with the highest protocol version present and ignore other protocol versions. returns a hash with keys :token, :app_uuid, and :signature parsed from the MCC-Authentication header if it is present and if not then the X-MWS-Authentication header if it is present. Note MWSV2 protocol no longer allows more than one space between the token and app uuid.



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mauth/request_and_response.rb', line 123

def signature_info
  @signature_info ||= begin
    match = if mcc_authentication
      mcc_authentication.match(
        /\A(#{MAuth::Client::MWSV2_TOKEN}) ([^:]+):([^:]+)#{MAuth::Client::AUTH_HEADER_DELIMITER}\z/
      )
    elsif x_mws_authentication
      x_mws_authentication.match(/\A([^ ]+) *([^:]+):([^:]+)\z/)
    end

    match ? { token: match[1], app_uuid: match[2], signature: match[3] } : {}
  end
end

#signature_tokenObject



141
142
143
# File 'lib/mauth/request_and_response.rb', line 141

def signature_token
  signature_info[:token]
end