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

帅比萌擦擦* 提交于 2019-12-18 04:40:48

问题


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_APP_ID'], ENV['FB_APP_SECRET'] in my config/initializers/devise.rb, devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } in my routes.rb, and an OmniAuthCallbacks controller defined.

When I visit user_omniauth_authorize_path(:facebook), I get: Not found. Authentication passthru. I'm not sure what to do next. I am not using route globing, so I don't believe I need to define a passthru method, but doing so just gives me a 404.


回答1:


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]



回答2:


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.




回答3:


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.




回答4:


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




回答5:


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.




回答6:


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




回答7:


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



来源:https://stackoverflow.com/questions/13812844/devise-omniauth-facebook-not-found-authentication-passthru

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