捆绑包更新后 FB-omniauth 损坏,凭据无效

Broken FB-omniauth after bundle update, invalid credentials

oauth 数据不会进入控制器操作。不明白怎么了。此控制器中还有一个身份验证提供程序,并且运行良好,核心完全相同。

devise  3.5.10 
rails 4.2.4

devise.rb
config.omniauth :facebook, Figaro.env.fb_app_id, Figaro.env.fb_app_secret, callback_url: 'https://chotam.ru/users/auth/facebook/callback',
                  scope: 'email, publish_actions'

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

def facebook
    logger.error "fb here" # IT'S NO OUTPUT HERE ON REQUEST!!!
    logger.error(request.env['omniauth.auth'])
    result = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
    @user = result[:user]
    status = result[:status]
    if @user
      token = request.env["omniauth.auth"]["credentials"]["token"]
      @user.account.update_attribute(:fb_token, token)
      if status[:redirect] == 'added' || status[:redirect] == 'existed'
        flash[status[:key]] = status[:value]
        render 'devise/registrations/edit'
      else
        flash[status[:key]] = status[:value]
        sign_in_and_redirect @user, event: :authentication
      end
    else
      flash[status[:key]] = status[:value]
      redirect_to new_user_registration_url
    end
  end

更新 使用记录器我可以看到以下内容:

E, [2017-03-28T23:46:41.255481 #21494] ERROR -- : (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
{"access_token":"real_token","token_type":"bearer"$

如何发现问题所在? 而且我还发现用户不能再更改他们的密码了。

试试这个。您必须更新 facebook-omniauth gem。 How to fix invalid credential? omniauth-facebook gem broken after Facebook API Deprecation.

在这里花了很多时间,才修复 - omniauth-facebook issue

好的...找到了一种无需更新 gem 的方法。

您可以在 config/initializers/devise.rb 文件的 config.omniauth 行添加以下内容:

client_options: {
  site: "https://graph.facebook.com/v2.3",
  authorize_url: "https://www.facebook.com/v2.3/dialog/oauth"
},
token_params: {
  parse: :json
}

具有完整配置的 YMMV,但它看起来像这样:

config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"],
    scope: 'email',
    secure_image_url: true,
    auth_type: 'https',
    info_fields: 'email,name,first_name,last_name',
    client_options: {
        site: "https://graph.facebook.com/v2.3",
        authorize_url: "https://www.facebook.com/v2.3/dialog/oauth"
    },
    token_params: {
        parse: :json
    }

主要问题是他们升级了响应格式,如果没有强制版本指针和令牌参数来解析新的 json 格式(而不是 url 编码格式),它会中断在响应中,因为它无法识别从 api.

吐回的内容