Devise, OmniAuth & Facebook: “Not found. Authentication passthru.”

前端 未结 9 1142
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-16 16:59

Trying to follow along with https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview and I\'m stumped.

I\'ve got config.omniauth :facebook, ENV[\'FB_AP

相关标签:
9条回答
  • 2020-12-16 17:22

    Try setting omniauth_path_prefix in devise initializer (config/initializers/devise.rb) file.

    For User class:

    config.omniauth_path_prefix = "/users/auth"
    

    For other class (e.g. when you use Account not User):

    config.omniauth_path_prefix = "/accounts/auth"
    

    Same thing with translated routes (my case). I've tranlated 'users' into 'blabla'. To have it working I had to set prefix to "/blabla/auth". (Works for only one locale!)

    0 讨论(0)
  • 2020-12-16 17:23

    Also make sure you have added a route to the OmniauthCallbacksController:

    devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
    

    and that you have added the update to the devise declaration in your User model:

    devise :omniauthable, :omniauth_providers => [:facebook]
    
    0 讨论(0)
  • 2020-12-16 17:25

    Make sure to write the same spelling of providers on both user.rb and devise.rb like -

    user.rb

    devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, omniauth_providers: [:google_oauth2, :facebook], authentication_keys: [:login], reset_password_keys: [:login], confirmation_keys: [:login]
    

    devise.rb

    config.omniauth :google_oauth2, ENV["GOOGLE_OAUTH_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],   
    {
        scope: 'userinfo.email, userinfo.profile',
        prompt: 'select_account',
        image_aspect_ratio: 'square',
        image_size: 50
      }
    
    config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], scope: 'email', info_fields: 'email, first_name, last_name', callback_url: "#{ENV["HOST_URL"]}/users/auth/facebook/callback"
    
    0 讨论(0)
提交回复
热议问题