-
-
Save bogdanRada/cf00272f4108e06a346c26fc10e9a5f8 to your computer and use it in GitHub Desktop.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment