运维开发网

ruby-on-rails – 使用Devise和Omniauth的路由问题

运维开发网 https://www.qedev.com 2020-05-29 10:10 出处:网络 作者:运维开发网整理
我试图让OAuth和Devise一起工作,但我得到Controller :: RoutingError(没有路由匹配“/ users / auth / facebook / callback”):当试图通过Facebook验证时. 奇怪的是,Google Apps不会出现此问题. (相同的回调路线). 有任何想法吗? callback_controller: class Users::Omniau
我试图让OAuth和Devise一起工作,但我得到Controller :: RoutingError(没有路由匹配“/ users / auth / facebook / callback”):当试图通过Facebook验证时.

奇怪的是,Google Apps不会出现此问题. (相同的回调路线).

有任何想法吗?

callback_controller:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def facebook
    # You need to implement the method below in your model
    @user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.facebook_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def google_apps
    @user = User.find_for_google_apps_oauth(env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google Apps"
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.google_apps_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def passthru
    render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end

end

routes.rb中:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

为什么:provider => “facebook”触发RoutingError,但不是:provider => “GOOGLE_APPS”?

找到了:

在设计用户模型中,我有模块:: omniauth_providers => [:facebook,:openid,:google_apps]添加了(显然)没有按照我的想法做到.我删除了该行,现在我的所有auth逻辑再次正常工作.

0

精彩评论

暂无评论...
验证码 换一张
取 消