I am trying to implement omniauth facebook for an application I am deploying to heroku.
I get the following message:
We're sorry, but something went wrong. If you are the application owner check the logs for more information.
When clicking over:
<%- 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 %>
In /config/devise.rb I Have:
# ==> 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'
and these are the logs:
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
I have already added the callback link to Valid OAuth Redirect URIs in developers.facebook
https://pentalingo.herokuapp.com/users/auth/facebook/callback
The methods in my models/users/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
in my users model I have:
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
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column users.provider does not exist
Looks like you need to add a provider
column to your User model.