Skip to content
Permalink
Browse files

fix redirect uri format in Client#request

  • Loading branch information...
SophieDeBenedetto committed Jul 19, 2016
1 parent fb502c7 commit bf389481ec02f65aa2885a787dbbad342af084a3
Showing with 8 additions and 2 deletions.
  1. +8 −2 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

This comment has been minimized.

Copy link
@aviflombaum

aviflombaum Aug 2, 2016

Member

I think this is slightly clearn for LOC 92-98

body = if opts[:body]      
  opts[:body][:redirect_uri] = opts[:body][:redirect_uri].split("?").first
  URI.encode_www_form(opts[:body])
else
  opts
end

I'm also wondering if you really need to re-write opts[:body][:redirect_uri] and can rather leave the original value alone and do something like:

body = opts[:body] ? URI.encode_www_form(opts[:body][:redirect_uri].split("?").first) : opts

I would also suggest naming what you're doing with opts[:body][:redirect_uri].split("?").first it's some sort of sanitation and a private method seems like a good home so that you get something like:

body = opts[:body] ? URI.encode_www_form(sanitize_querystring_on_body_rediect_uri) : opts

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])

0 comments on commit bf38948

Please sign in to comment.
You can’t perform that action at this time.