Module: MAuth::Client::Signer
- Included in:
- MAuth::Client
- Defined in:
- lib/mauth/client.rb
Overview
methods to sign requests and responses. part of MAuth::Client
Instance Method Summary collapse
-
#signature(object, attributes = {}) ⇒ Object
takes a signable object (outgoing request or response).
-
#signed(object, attributes = {}) ⇒ Object
takes an outgoing request or response object, and returns an object of the same class whose headers are updated to include mauth’s signature headers.
-
#signed_headers(object, attributes = {}) ⇒ Object
takes a signable object (outgoing request or response).
Instance Method Details
#signature(object, attributes = {}) ⇒ Object
takes a signable object (outgoing request or response). returns a mauth signature string for that object.
255 256 257 258 259 |
# File 'lib/mauth/client.rb', line 255 def signature(object, attributes = {}) assert_private_key(UnableToSignError.new("mAuth client cannot sign without a private key!")) attributes = { time: Time.now.to_i.to_s, app_uuid: client_app_uuid }.merge(attributes) signature = Base64.encode64(private_key.private_encrypt(object.string_to_sign(attributes))).delete("\n") end |
#signed(object, attributes = {}) ⇒ Object
takes an outgoing request or response object, and returns an object of the same class whose headers are updated to include mauth’s signature headers
241 242 243 |
# File 'lib/mauth/client.rb', line 241 def signed(object, attributes = {}) object.merge_headers(signed_headers(object, attributes)) end |
#signed_headers(object, attributes = {}) ⇒ Object
takes a signable object (outgoing request or response). returns a hash of headers to be applied tothe object which comprise its signature.
247 248 249 250 251 |
# File 'lib/mauth/client.rb', line 247 def signed_headers(object, attributes = {}) attributes = { time: Time.now.to_i.to_s, app_uuid: client_app_uuid }.merge(attributes) signature = self.signature(object, attributes) { 'X-MWS-Authentication' => "#{MWS_TOKEN} #{client_app_uuid}:#{signature}", 'X-MWS-Time' => attributes[:time] } end |