Browse files

Merging #40

  • Loading branch information...
1 parent 470db19 commit a9f11558b75ff1aa6272b47bb4d9805d4c01d142 @shayne shayne committed Jul 13, 2012
Showing with 9 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +8 −5 lib/faraday/oauth2.rb
View
1 .gitignore
@@ -10,3 +10,4 @@ coverage/*
doc/*
log/*
pkg/*
+.idea/*
View
13 lib/faraday/oauth2.rb
@@ -7,13 +7,17 @@ class OAuth2 < Faraday::Middleware
def call(env)
if env[:method] == :get or env[:method] == :delete
- env[:url].query_values = {} if env[:url].query_values.nil?
+ if env[:url].query.nil?
+ query = {}
+ else
+ query = Faraday::Utils.parse_query(env[:url].query)
+ end
- if @access_token and not env[:url].query_values["client_secret"]
- env[:url].query_values = env[:url].query_values.merge(:access_token => @access_token)
+ if @access_token and not query["client_secret"]
+ env[:url].query = Faraday::Utils.build_query(query.merge(:access_token => @access_token))
env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
elsif @client_id
- env[:url].query_values = env[:url].query_values.merge(:client_id => @client_id)
+ env[:url].query = Faraday::Utils.build_query(query.merge(:client_id => @client_id))
end
else
if @access_token and not env[:body] && env[:body][:client_secret]
@@ -25,7 +29,6 @@ def call(env)
end
end
- env[:url].query_values = nil if env[:url].query_values == {}
@app.call env
end

0 comments on commit a9f1155

Please sign in to comment.