From bf389481ec02f65aa2885a787dbbad342af084a3 Mon Sep 17 00:00:00 2001 From: SOPHIE DEBENEDETTO Date: Tue, 19 Jul 2016 08:08:27 -0400 Subject: [PATCH 1/2] fix redirect uri format in Client#request --- lib/oauth2/client.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/oauth2/client.rb b/lib/oauth2/client.rb index cb1b5648..e421fe9a 100644 --- a/lib/oauth2/client.rb +++ b/lib/oauth2/client.rb @@ -89,8 +89,14 @@ def request(verb, url, opts = {}) # rubocop:disable CyclomaticComplexity, Method connection.response :logger, ::Logger.new($stdout) if ENV['OAUTH_DEBUG'] == 'true' url = connection.build_url(url, opts[:params]).to_s - - response = connection.run_request(verb, url, opts[:body], opts[:headers]) do |req| + body = nil + if opts[:body] + opts[:body][:redirect_uri] = opts[:body][:redirect_uri].split("?").first + body = URI.encode_www_form(opts[:body]) + else + body = opts + end + response = connection.run_request(verb, url, body, opts[:headers]) do |req| yield(req) if block_given? end response = Response.new(response, :parse => opts[:parse]) From 2ad89783bc140a944a24a579b949e2c2f9385d64 Mon Sep 17 00:00:00 2001 From: SOPHIE DEBENEDETTO Date: Tue, 2 Aug 2016 15:36:46 -0400 Subject: [PATCH 2/2] clean up redirect uri parsing patch, passing all tests --- lib/oauth2/client.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/oauth2/client.rb b/lib/oauth2/client.rb index e421fe9a..c5667a78 100644 --- a/lib/oauth2/client.rb +++ b/lib/oauth2/client.rb @@ -89,18 +89,16 @@ def request(verb, url, opts = {}) # rubocop:disable CyclomaticComplexity, Method connection.response :logger, ::Logger.new($stdout) if ENV['OAUTH_DEBUG'] == 'true' url = connection.build_url(url, opts[:params]).to_s - body = nil - if opts[:body] - opts[:body][:redirect_uri] = opts[:body][:redirect_uri].split("?").first - body = URI.encode_www_form(opts[:body]) + body = if opts[:body] && opts[:body].is_a?(Hash) && opts[:body][:redirect_uri] + opts[:body][:redirect_uri] = sanitize_querystring_on_body_rediect_uri(opts) + URI.encode_www_form(opts[:body]) else - body = opts - end + opts[:body] + end response = connection.run_request(verb, url, body, opts[:headers]) do |req| yield(req) if block_given? end response = Response.new(response, :parse => opts[:parse]) - case response.status when 301, 302, 303, 307 opts[:redirect_count] ||= 0 @@ -178,5 +176,11 @@ def client_credentials def assertion @assertion ||= OAuth2::Strategy::Assertion.new(self) end + + private + + def sanitize_querystring_on_body_rediect_uri(opts) + opts[:body][:redirect_uri].split("?").first + end end end