ruby 猴子补丁修复身份验证失败! invalid_credentials:OAuth2 ::错误jruby 8,rails 3.2.13 devise 3.2.4 |迫使法拉第'uncom

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 猴子补丁修复身份验证失败! invalid_credentials:OAuth2 ::错误jruby 8,rails 3.2.13 devise 3.2.4 |迫使法拉第'uncom相关的知识,希望对你有一定的参考价值。

# 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

以上是关于ruby 猴子补丁修复身份验证失败! invalid_credentials:OAuth2 ::错误jruby 8,rails 3.2.13 devise 3.2.4 |迫使法拉第'uncom的主要内容,如果未能解决你的问题,请参考以下文章

您如何检测到 Ruby 中发生了猴子补丁?

ruby 因为没人喜欢猴子补丁。

ruby 猴子补丁模式

ruby 猴子补丁模式

ruby 猴子补丁用keen.io保存查询

寻找可能导致麻烦的 Ruby 猴子补丁的来源?