尝试将omniauth facebook与rails集成并部署到heroku时无法登录

时间:2019-10-04 17:14:23

标签: ruby-on-rails heroku omniauth-facebook

我正在尝试为要部署到heroku的应用程序实现omniauth facebook。

我收到以下消息:

  

很抱歉,出了点问题。如果您是申请者   所有者检查日志以获取更多信息。

单击时

<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
    <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
  <% end %>

在/config/devise.rb中,我有:

  # ==> OmniAuth
  # Add a new OmniAuth provider. Check the wiki for more information on setting
  # up on your models and hooks.
  config.omniauth :facebook, '***', '***', 
  scope: 'email',
  info_fields: 'email',
  secure_image_url: true,
  image_size: 'large',
  token_params: { parse: :json },
  callback_url: 'https://pentalingo.herokuapp.com/users/auth/facebook/callback'

这些是日志:

 dyno=web.1 connect=1ms service=33ms status=302 bytes=1197 protocol=https
2019-10-04T16:52:08.641707+00:00 app[web.1]: I, [2019-10-04T16:52:08.641611 #4]  INFO -- : [fcfdf06f-ac86-403e-b3e8-0630204bd5e6] Started GET "/users/auth/facebook" for 46.24.93.212 at 2019-10-04 16:52:08 +0000
2019-10-04T16:52:08.642218+00:00 app[web.1]: I, [2019-10-04T16:52:08.642144 #4]  INFO -- omniauth: (facebook) Request phase initiated.
2019-10-04T16:52:09.301754+00:00 app[web.1]: I, [2019-10-04T16:52:09.301658 #4]  INFO -- : [3971d9a5-d629-4e86-a0a1-157dfdc396c6] Started GET "/users/auth/facebook" for 46.24.93.212 at 2019-10-04 16:52:09 +0000
2019-10-04T16:52:09.302090+00:00 app[web.1]: I, [2019-10-04T16:52:09.302037 #4]  INFO -- omniauth: (facebook) Request phase initiated.
2019-10-04T16:52:09.302778+00:00 heroku[router]: at=info method=GET path="/users/auth/facebook" host=pentalingo.herokuapp.com request_id=3971d9a5-d629-4e86-a0a1-157dfdc396c6 fwd="46.24.93.212" dyno=web.1 connect=1ms service=4ms status=302 bytes=1197 protocol=https
2019-10-04T16:52:10.220974+00:00 app[web.1]: I, [2019-10-04T16:52:10.220880 #4]  INFO -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6] Started GET "/users/auth/facebook/callback?code=AQDSIo5-TFkKDII-ncfdoy0sJe2K2zXK5Gzlr6b0hQjpzKwcaKqGXPC10QMiSCpM4bU0FvcImY9ZFG5OJO3snOEgLC209DWBqIrNBbVCeiXj6kFrnRhBcMFP4mlbSleeuH2OutMN1cPIPSWFLorrOHp6BxcbABOh88NB9A12_iGxcVIUPj-hJWDm75xgEMv80sJqaEh_EHzgMFn2urP1QE8bG9lWRxvOX20BuLWrcJuIEcHIBtEH4TSyxjeaRM_6qmlvbRObxTZJ1MY-T7edOI3BfzXnF4oqPBBSpZRPtUcXjG48ZHN_lQMo36Ua86vodsi38ibWWPdj3JBzLuo9ajZV&state=0d915222bc5a9fd101bf721f12f2ce011f305a62c046e8ae" for 46.24.93.212 at 2019-10-04 16:52:10 +0000
2019-10-04T16:52:10.221356+00:00 app[web.1]: I, [2019-10-04T16:52:10.221262 #4]  INFO -- omniauth: (facebook) Callback phase initiated.
2019-10-04T16:52:10.545775+00:00 app[web.1]: I, [2019-10-04T16:52:10.545487 #4]  INFO -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6] Processing by Users::OmniauthCallbacksController#facebook as HTML
2019-10-04T16:52:10.545796+00:00 app[web.1]: I, [2019-10-04T16:52:10.545595 #4]  INFO -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6]   Parameters: {"code"=>"AQDSIo5-TFkKDII-ncfdoy0sJe2K2zXK5Gzlr6b0hQjpzKwcaKqGXPC10QMiSCpM4bU0FvcImY9ZFG5OJO3snOEgLC209DWBqIrNBbVCeiXj6kFrnRhBcMFP4mlbSleeuH2OutMN1cPIPSWFLorrOHp6BxcbABOh88NB9A12_iGxcVIUPj-hJWDm75xgEMv80sJqaEh_EHzgMFn2urP1QE8bG9lWRxvOX20BuLWrcJuIEcHIBtEH4TSyxjeaRM_6qmlvbRObxTZJ1MY-T7edOI3BfzXnF4oqPBBSpZRPtUcXjG48ZHN_lQMo36Ua86vodsi38ibWWPdj3JBzLuo9ajZV", "state"=>"0d915222bc5a9fd101bf721f12f2ce011f305a62c046e8ae"}
2019-10-04T16:52:10.552444+00:00 app[web.1]: I, [2019-10-04T16:52:10.552371 #4]  INFO -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6] Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.9ms)
2019-10-04T16:52:10.553072+00:00 app[web.1]: F, [2019-10-04T16:52:10.553001 #4] FATAL -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6]
2019-10-04T16:52:10.553136+00:00 app[web.1]: F, [2019-10-04T16:52:10.553075 #4] FATAL -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6] ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column users.provider does not exist
2019-10-04T16:52:10.553140+00:00 app[web.1]: LINE 1: SELECT  "users".* FROM "users" WHERE "users"."provider" = $1...
2019-10-04T16:52:10.553143+00:00 app[web.1]: ^
2019-10-04T16:52:10.553145+00:00 app[web.1]: : SELECT  "users".* FROM "users" WHERE "users"."provider" = $1 AND "users"."uid" = $2 ORDER BY "users"."id" ASC LIMIT $3):
2019-10-04T16:52:10.553167+00:00 app[web.1]: F, [2019-10-04T16:52:10.553124 #4] FATAL -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6]
2019-10-04T16:52:10.553254+00:00 app[web.1]: F, [2019-10-04T16:52:10.553182 #4] FATAL -- : [41fa5c92-4e10-4e90-962e-28265bb4dfc6] app/models/user.rb:54:in `from_omniauth'
2019-10-04T16:52:10.553256+00:00 app[web.1]: [41fa5c92-4e10-4e90-962e-28265bb4dfc6] app/controllers/users/omniauth_callbacks_controller.rb:3:in `facebook'
2019-10-04T16:52:10.552780+00:00 heroku[router]: at=info method=GET path="/users/auth/facebook/callback?code=AQDSIo5-TFkKDII-ncfdoy0sJe2K2zXK5Gzlr6b0hQjpzKwcaKqGXPC10QMiSCpM4bU0FvcImY9ZFG5OJO3snOEgLC209DWBqIrNBbVCeiXj6kFrnRhBcMFP4mlbSleeuH2OutMN1cPIPSWFLorrOHp6BxcbABOh88NB9A12_iGxcVIUPj-hJWDm75xgEMv80sJqaEh_EHzgMFn2urP1QE8bG9lWRxvOX20BuLWrcJuIEcHIBtEH4TSyxjeaRM_6qmlvbRObxTZJ1MY-T7edOI3BfzXnF4oqPBBSpZRPtUcXjG48ZHN_lQMo36Ua86vodsi38ibWWPdj3JBzLuo9ajZV&state=0d915222bc5a9fd101bf721f12f2ce011f305a62c046e8ae" host=pentalingo.herokuapp.com request_id=41fa5c92-4e10-4e90-962e-28265bb4dfc6 fwd="46.24.93.212" dyno=web.1 connect=1ms service=335ms status=500 bytes=1827 protocol=https

我已经在developer.facebook

中将回调链接添加到有效OAuth重定向URI。
https://pentalingo.herokuapp.com/users/auth/facebook/callback

我的模型/用户/omniauth_callbacks_controller.rb中的方法

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end
end

在我的用户模型中,我有:

  def self.new_with_session(params, session)
    super.tap do |user|
      if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
        user.email = data["email"] if user.email.blank?
      end
    end
  end

  def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
      user.email = auth.info.email
      user.password = Devise.friendly_token[0,20]
      user.name = auth.info.name   # assuming the user model has a name
      user.image = auth.info.image # assuming the user model has an image
    end
  end

1 个答案:

答案 0 :(得分:2)

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column users.provider does not exist

您似乎需要在用户模型中添加一个provider列。