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

馋奶兔 提交于 2019-11-29 06:13:36

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]
Alex Driaguine

So I've stumbeled upon this after opening a old project and and after seeing that my authorize url looke something like "user/auth/facebook.facebook" i ran a rake routes and solved it by changing

<%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %>

to

<%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>

Apparently the helpers for the omniauth routes have changed since the rake routes command returned:

user_facebook_omniauth_authorize   GET|POST   /users/auth/facebook(.:format)          omniauth_callbacks#passthru

and not as it was some months ago when I started the project.

user_omniauth_authorize            GET|POST   /users/auth/facebook(:provider)          omniauth_callbacks#passthru

Hope this post helps someone.

I had the same error.
What worked for me was restarting the rails server, to reflect the changes (config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET']) I had made to config/initializers/devise.rb.

I should have listed this sooner, but I ended up doing a "back out and retry" approach; I deleted everything I had related to OmniAuth and started over following the instructions. I wish I knew what, specifically, I had wrong but unfortunately it "just worked" once I retried.

tl;dr Follow the steps in https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview verbatim and it should work

For anyone who wants to know how to fix this, simply declare a passthru method, or do what I did, which is use action_missing (not method_missing, it is deprecated in Rails 4!) to catch all users/auth/:provider urls that omniauth uses in one method.

For instance,

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def action_missing(provider)
    # Set up authentication/authorizations here, and distribute tasks
    # that are provider specific to other methods, leaving only tasks
    # that work across all providers in this method. 
  end

I hope that helps anyone else who gets stuck here, I sure did.

I spent the entire day today trying to track down the issue and I finally found it while going back in git history since it used to work earlier.

It turned out that the routing-filter to switch locales somehow was the root of the evil. I just disabled the filter :locale method in my routes and the authorization request went through to facebook. Bloody hell, I'm so glad I finally found out about that :)

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!)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!