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

时间:2017-03-28 09:58:20

标签: ruby-on-rails-4 devise omniauth omniauth-facebook

oauth数据不会进入控制器操作。无法理解错误。在这个控制器中还有一个auth提供程序,它运行良好,核心完全相同。

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"$

如何找到错误的? 而且我发现用户不能再更改密码了。

2 个答案:

答案 0 :(得分:4)

好的......找到了一种不更新宝石的方法。

您可以在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吐了回来。

答案 1 :(得分:1)

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

在修复之前花了很多时间 - omniauth-facebook issue