From c1f8d5a85904e0946496b496009810b963af8828 Mon Sep 17 00:00:00 2001 From: Martyn Loughran Date: Thu, 21 Jun 2012 18:29:52 +0100 Subject: [PATCH] Add Request#signed_params method --- lib/signature.rb | 12 ++++++++++-- spec/signature_spec.rb | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/signature.rb b/lib/signature.rb index 9c03289..ecba0d5 100644 --- a/lib/signature.rb +++ b/lib/signature.rb @@ -34,6 +34,7 @@ def initialize(method, path, query) @method = method.upcase @path, @query_hash, @auth_hash = path, query_hash, auth_hash + @signed = false end # Sign the request with the given token, and return the computed @@ -45,9 +46,10 @@ def sign(token) :auth_key => token.key, :auth_timestamp => Time.now.to_i.to_s } - @auth_hash[:auth_signature] = signature(token) + @signed = true + return @auth_hash end @@ -111,10 +113,16 @@ def authenticate(timestamp_grace = 600) # Expose the authentication parameters for a signed request # def auth_hash - raise "Request not signed" unless @auth_hash && @auth_hash[:auth_signature] + raise "Request not signed" unless @signed @auth_hash end + # Query parameters merged with the computed authentication parameters + # + def signed_params + @query_hash.merge(auth_hash) + end + private def signature(token) diff --git a/spec/signature_spec.rb b/spec/signature_spec.rb index 8b9ccc4..35be3a4 100644 --- a/spec/signature_spec.rb +++ b/spec/signature_spec.rb @@ -84,7 +84,7 @@ describe "verification" do before :each do @request.sign(@token) - @params = @request.query_hash.merge(@request.auth_hash) + @params = @request.signed_params end it "should verify requests" do