Permalink
Browse files

Experiment with computing a signature.

  • Loading branch information...
1 parent 1a9ff35 commit d088337440d9147f8acb24b48825955da2f90fb1 @Manfred Manfred committed Sep 17, 2011
Showing with 26 additions and 9 deletions.
  1. +18 −5 lib/roaund.rb
  2. +8 −4 lib/roaund/token.rb
View
@@ -3,6 +3,7 @@
class Roaund
autoload :Token, 'roaund/token'
+
class << self
attr_accessor :temporary_credential_request_url,
:resource_owner_authorization_url,
@@ -27,6 +28,16 @@ def initiate
end
end
+ def signature_base
+ [
+ request.method,
+ request.host,
+ request.path_and_query,
+ authorization_as_hash.except('oauth_signature'),
+ request.body_params
+ ].map { |part| CGI.escape(part) }.join('&')
+ end
+
def authorization_as_hash
authorization_as_hash = {
'oauth_consumer_key' => @consumer_key,
@@ -39,11 +50,7 @@ def authorization_as_hash
end
def authorization
- parts = ["OAuth realm=\"#{@realm}\""]
- authorization_as_hash.each do |key, value|
- parts << "#{CGI.escape(key)}=\"#{CGI.escape(value)}\""
- end
- parts.join(',')
+ "Oauth #{_pairs_to_header_options(authorization_as_hash.merge('Realm' => @realm))}"
end
def token(params_as_string)
@@ -52,4 +59,10 @@ def token(params_as_string)
token.parse(params_as_string)
token
end
+
+ def _pairs_to_header_options(pairs)
+ encoded = []; for (key, value) in pairs
+ encoded << "#{CGI.escape(key)}=\"#{CGI.escape(value||'')}\""
+ end; encoded.join(',')
+ end
end
View
@@ -12,12 +12,16 @@ def load(input)
end
def dump
- [
+ _pairs_to_query_part([
['oauth_token', @token],
['oauth_token_secret', @secret]
- ].inject([]) do |parts, (key, value)|
- parts << "#{CGI.escape(key)}=#{CGI.escape(value)}"
- end.join('&')
+ ])
+ end
+
+ def _pairs_to_query_part(pairs)
+ encoded = []; for (key, value) in pairs
+ encoded << "#{CGI.escape(key)}=#{CGI.escape(value||'')}"
+ end; encoded.join('&')
end
def self.dump(token)

0 comments on commit d088337

Please sign in to comment.