lib/simple_oauth.rb in simple_oauth-0.1.0 vs lib/simple_oauth.rb in simple_oauth-0.1.1

- old
+ new

@@ -5,11 +5,11 @@ module SimpleOAuth module Version MAJOR = 0 MINOR = 1 - PATCH = 0 + PATCH = 1 STRING = [MAJOR, MINOR, PATCH].join('.') end class Header ATTRIBUTE_KEYS = [:consumer_key, :nonce, :signature_method, :timestamp, :token, :version] @@ -67,11 +67,11 @@ valid end private def normalized_attributes - signed_attributes.sort_by(&:to_s).map{|k,v| %(#{k}="#{self.class.encode(v)}") }.join(', ') + signed_attributes.sort_by{|k,v| k.to_s }.map{|k,v| %(#{k}="#{self.class.encode(v)}") }.join(', ') end def signed_attributes attributes.merge(:oauth_signature => signature) end @@ -83,35 +83,39 @@ def signature send(options[:signature_method].downcase.tr('-', '_') + '_signature') end def hmac_sha1_signature - Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret, signature_base)).chomp + Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret, signature_base)).chomp.gsub(/\n/, '') end - def rsa_sha1_signature - Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), options[:private_key].to_s, signature_base)).chomp - end - def secret options.values_at(:consumer_secret, :token_secret).map{|v| self.class.encode(v) }.join('&') end - alias_method :plaintext_signature, :secret - def signature_base [method, url, normalized_params].map{|v| self.class.encode(v) }.join('&') end def normalized_params - signature_params.sort_by(&:to_s).map{|p| p.map{|v| self.class.encode(v) }.join('=') }.join('&') + signature_params.map{|p| p.map{|v| self.class.encode(v) } }.sort.map{|p| p.join('=') }.join('&') end def signature_params attributes.to_a + params.to_a + url_params end def url_params CGI.parse(@uri.query || '').inject([]){|p,(k,vs)| p + vs.map{|v| [k, v] } } end + + def rsa_sha1_signature + Base64.encode64(private_key.sign(OpenSSL::Digest::SHA1.new, signature_base)).chomp.gsub(/\n/, '') + end + + def private_key + OpenSSL::PKey::RSA.new(options[:consumer_secret]) + end + + alias_method :plaintext_signature, :secret end end