Monkey patch to fix Authentication failure! invalid_credentials: OAuth2::Error jruby 8 , rails 3.2.13 devise 3.2.4 | Force faraday to 'uncompressed' gzip
# In Rails, add this to your Initializer/ folder
#
# Fix by @richardsondx - Richardson Dackam
#
# Thi monkey patch is not actually forcing farady to uncompress the response but it's telling it not to compress
# So it forces Faraday to avoid compressing the response.
# The gresponse from google had the header 'accept-encoding': 'gzip'
# unlike http.net, http.request doesn't automatically uncompress gzip request
# more info about http.request at https://github.com/ruby/ruby/blob/ruby_2_2/lib/net/http.rb
module Faraday
class Request::UrlEncoded < Faraday::Middleware
def call(env)
match_content_type(env) do |data|
params = Faraday::Utils::ParamsHash[data]
env.body = params.to_query(env.params_encoder)
if env.url.to_s == "https://accounts.google.com/o/oauth2/token"
# Will remove any encoding that is happended for that url
env.request_headers['accept-encoding'] = ''
# The following call might be cleanner as it make sure that the response is not gzip*
# env.request_headers["accept-encoding"] = "gzip;q=0,deflate,sdch"
end
end
@app.call env
end
end
end