简体   繁体   English

未找到。 身份验证直通。 (设计oauth facebook)

[英]Not found. Authentication passthru. (devise oauth facebook)

I am setting up the login/registration with facebook (devise), but as other people, I have no luck to make it working. 我正在使用facebook(设计)设置登录/注册,但是作为其他人,我没有运气来使其正常运行。 I have read lots of posts and articles from other people and went through the settings several times, but still the same results. 我阅读了很多其他人的帖子和文章,并多次进行了设置,但结果仍然相同。

When I click on the "Log in with Facebook" button, I get the message "Not found. Authentication passthru". 当我单击“使用Facebook登录”按钮时,收到消息“未找到。身份验证通过”。

It has never went though the "facebook" controller action, but always through the "passthru" action. 它从来没有通过“ facebook”控制器动作,而是始终通过“ passthru”动作。

I use: - rake v2.3.0 - rails v4.2.3 - devise v3.5.2 我使用:-rake v2.3.0-rails v4.2.3-devise v3.5.2

Thank you for any help. 感谢您的任何帮助。 Miroslav 米罗斯拉夫


omniauth_callbacks_controller.rb omn​​iauth_callbacks_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  # You should configure your model like this:

  # You should also create an action method in this controller like this:
  def facebook
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      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

  # More info at:
  # https://github.com/plataformatec/devise#omniauth

  # GET|POST /resource/auth/facebook
  def passthru
    super
  end

  # GET|POST /users/auth/facebook/callback
  def failure
    super
  #redirect_to root_path
  end

  # protected

  # The path used when OmniAuth fails
  def after_omniauth_failure_path_for(scope)
    super(scope)
  end

  #def failure
  #  redirect_to root_path
  #end

end

User.rb User.rb

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :confirmable, 
     :recoverable, :rememberable, :trackable, :omniauthable, :validatable, password_length: 6..72, :omniauth_providers => [:facebook]

  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.rolable.firstname = auth.info.firstname   # assuming the user model has a name
      user.rolable.lastname = auth.info.lastname
      user.image = auth.info.image # assuming the user model has an image
      # If you are using confirmable and the provider(s) you use validate emails, 
      # uncomment the line below to skip the confirmation emails.
      # user.skip_confirmation!
    end
  end

end

devise.rb devise.rb

Devise.setup do |config|  
  config.mailer = 'CustomDeviseMailer'

  require 'devise/orm/active_record'

  config.case_insensitive_keys = [:email]
  config.strip_whitespace_keys = [:email]
  config.http_authenticatable_on_xhr = false
  config.skip_session_storage = [:http_auth]
  config.stretches = Rails.env.test? ? 1 : 10 
  config.allow_unconfirmed_access_for = 1.days
  config.reconfirmable = false
  config.expire_all_remember_me_on_sign_out = true
  config.password_length = 6..72
  config.reset_password_within = 24.hours
  config.sign_out_via = :delete
  config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET']

end

routes.rb routes.rb

devise_for :users, path: "auth", :controllers => {sessions: 'sessions', registrations: 'registrations', confirmations: 'confirmations', passwords: 'passwords', omniauth_callbacks: 'omniauth_callbacks'} 

rake routes 耙路

user_omniauth_authorize_en GET|POST /en/auth/auth/:provider(.:format)                                                                  omniauth_callbacks#passthru {:locale=>"en", :provider=>/facebook/}
user_omniauth_authorize_ma GET|POST /ma/auth/auth/:provider(.:format)                                                                  omniauth_callbacks#passthru {:locale=>"ma", :provider=>/facebook/}
user_omniauth_authorize_cs GET|POST /cs/auth/auth/:provider(.:format)                                                                  omniauth_callbacks#passthru {:locale=>"cs", :provider=>/facebook/}
user_omniauth_callback_en GET|POST /en/auth/auth/:action/callback(.:format)                                                           omniauth_callbacks#(?-mix:facebook) {:locale=>"en"}
user_omniauth_callback_ma GET|POST /ma/auth/auth/:action/callback(.:format)                                                           omniauth_callbacks#(?-mix:facebook) {:locale=>"ma"}
user_omniauth_callback_cs GET|POST /cs/auth/auth/:action/callback(.:format)                                                           omniauth_callbacks#(?-mix:facebook) {:locale=>"cs"}

login.html.erb login.html.erb

<%= button_to t(:login_form_link_facebook), user_omniauth_authorize_path(:facebook), :title => t(:login_form_link_facebook), :class => "btn btn-fcb full-w capital semi-margin-bottom bold", :method => :get %>

My issue was with routes. 我的问题是路线。 I was using localized urls and it was causing issues with facebook omniauth. 我正在使用本地化的URL,这导致了Facebook omniauth的问题。

Instead of: 代替:

localized do
    devise_for :users, path: "auth", :controllers => {sessions: 'sessions', registrations: 'registrations', confirmations: 'confirmations', passwords: 'passwords', omniauth_callbacks: 'omniauth_callbacks'} 
end

I used: 我用了:

devise_for :users, path: "auth", :controllers => {sessions: 'sessions', registrations: 'registrations', confirmations: 'confirmations', passwords: 'passwords', omniauth_callbacks: 'omniauth_callbacks'} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设计、OmniAuth 和 Facebook:“未找到。身份验证通路。” - Devise, OmniAuth & Facebook: "Not found. Authentication passthru." 未找到。 身份验证直通。 stripe_connect和设计 - Not found. Authentication passthru. stripe_connect and Devise Rails google-oauth2 404 -“未找到。身份验证通路。” - Rails google-oauth2 404 - "Not found. Authentication passthru." 设计/谷歌 OAuth 2:未找到。 认证通路 - Devise/Google OAuth 2: Not found. Authentication passthru 谷歌 OAuth 2.0 + Ruby on Rails 404:“未找到。 身份验证通道。” - Google OAuth 2.0 + Ruby on Rails 404: “Not found. Authentication passthru.” “未找到。 身份验证passthru。“错误。 当它在另一个引擎内部时,Devise Omniauthable模块不起作用 - “Not found. Authentication passthru.” error. Devise Omniauthable module doesn't work when it's inside another engine Devise Omniauth + Facebook错误找不到。 认证通过 - Devise Omniauth + Facebook Error Not found. Authentication passthru Devise + OmniAuth Instagram:找不到。 认证通过 - Devise + OmniAuth Instagram: Not found. Authentication passthru 我该如何解决错误`未找到。 Omniauth GitHub 的身份验证通路。 - How can I solve the error `Not found. Authentication passthru.` for Omniauth GitHub? 我一直得到“没找到。 身份验证passthru“for Facebook连接与Devise登录 - 需要调试建议 - I keep getting “Not found. Authentication passthru” for Facebook connect login with Devise - Need debug advice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM