Skip to content
Browse files

safe merge of dumplicate keys in request, post parameters

  • Loading branch information...
1 parent 81a43bb commit 7c1aaef6b5f7f2bc1474e007b98c6e770e42526b hattori committed Apr 22, 2011
View
6 lib/opensocial-wap/oauth/helpers/basic_helper.rb
@@ -15,7 +15,11 @@ def self.setup(options)
end
def verify(options = nil)
- request_proxy = ::OAuth::RequestProxy.proxy(@request)
+ if self.class.proxy_class
+ request_proxy = self.class.proxy_class.new(@request)
+ else
+ request_proxy = ::OAuth::RequestProxy.proxy(@request)
+ end
opts = {
:consumer_secret => self.class.consumer_secret,
:token_secret => request_proxy.parameters['oauth_token_secret'] }
View
66 lib/opensocial-wap/oauth/request_proxy/oauth_rack_request_proxy.rb
@@ -0,0 +1,66 @@
+require 'oauth/request_proxy/rack_request'
+
+module OpensocialWap::OAuth::RequestProxy
+ class OAuthRackRequestProxy < OAuth::RequestProxy::RackRequest
+
+ def normalized_parameters
+ normalize(my_parameters_for_signature)
+ end
+
+ def my_parameters_for_signature
+ my_parameters.reject { |k,v| k == "oauth_signature" || unsigned_parameters.include?(k)}
+ end
+
+ def my_parameters
+ merged_params = merge query_params_hash, request_params_hash
+ merged_params = merge merged_params, header_params
+ end
+
+ private
+
+ def query_params_hash
+ parse_params request.query_string
+ end
+
+
+ def request_params_hash
+ post = request.POST
+ parse_params request.env['rack.request.form_vars']
+ end
+
+ # request.POST は env["rack.request.form_hash"] の値を返すが、POSTデータ中に
+ # "..var%5Bkey%5D=123.." のような部分があると、"var"=>{"key"=>"123"} という
+ # 形式に変換してしまう.
+ # これを、"var[key]"=>"123" を返すように修正する.
+ def parse_params params_str
+ if params_str && params_str.size > 0
+ params_str.split('&').inject({}) do |hsh, i|
+ kv = i.split('=')
+ key = ::Rack::Utils::unescape(kv[0])
+ if hsh[key]
+ hsh[key] << kv[1] ? ::Rack::Utils::unescape(kv[1]) : ''
+ else
+ hsh[key] = [kv[1] ? ::Rack::Utils::unescape(kv[1]) : '']
+ end
+ hsh
+ end
+ else
+ {}
+ end
+ end
+
+ def merge hash1, hash2
+ result = hash1.dup
+ hash2.each do |k,v|
+ v = [v] unless v.is_a? Array
+ if result[k]
+ result[k] += v
+ else
+ result[k] = v
+ end
+ end
+ result
+ end
+
+ end
+end
View
11 lib/opensocial-wap/oauth/request_proxy/oauth_rack_request_proxy_for_mixi.rb
@@ -0,0 +1,11 @@
+require 'opensocial-wap/oauth/request_proxy/oauth_rack_request_proxy'
+
+module OpensocialWap::OAuth::RequestProxy
+ class OAuthRackRequestProxyForMixi < OAuthRackRequestProxy
+
+ def my_parameters
+ merged_params = merge query_params_hash, header_params
+ end
+
+ end
+end

0 comments on commit 7c1aaef

Please sign in to comment.
Something went wrong with that request. Please try again.