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.
279 280 281 282 283 |
# File 'lib/mauth/client.rb', line 279 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
265 266 267 |
# File 'lib/mauth/client.rb', line 265 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.
271 272 273 274 275 |
# File 'lib/mauth/client.rb', line 271 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 |