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

前端 未结 9 1141
爱一瞬间的悲伤
爱一瞬间的悲伤 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:01

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

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

    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.

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

    It could be happening because the configuration with Devise and Omniauth should be made ONLY in config/initializers/devise.rb. Do not create the onfig/initializers/omniauth.rb file.

    Remember that config.omniauth adds omniauth provider middleware to your application. This means you should not add this provider middleware again in config/initializers/omniauth.rb as they'll clash with each other and result in always-failing authentication.

    https://github.com/heartcombo/devise/wiki/OmniAuth%3A-Overview#before-you-start

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

    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.

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

    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.

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

    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

    0 讨论(0)
提交回复
热议问题