【问题标题】:Problem with Routes using Devise and Omniauth使用 Devise 和 Omniauth 的路由问题
【发布时间】:2011-06-14 05:40:51
【问题描述】:

我正在尝试让 OAuth 和 Devise 协同工作,但在尝试通过 Facebook 进行身份验证时我收到了Controller::RoutingError (No route matches "/users/auth/facebook/callback"):

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

有什么想法吗?

回调控制器:

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 =&gt; "facebook" 会触发 RoutingError,而不是:provider =&gt; "google_apps"

【问题讨论】:

  • 是您在app/controllers/users/omniauth_callbacks_controller.rb?中的文件
  • 是的!就像我说的 - 谷歌的工作正常 - 它只是在使用 Facebook 时。

标签: ruby-on-rails routes devise omniauth


【解决方案1】:

找到了:

在设计用户模型中,我添加了模块::omniauth_providers =&gt; [:facebook, :openid, :google_apps],它(显然)没有按照我的想法做。我删除了该行,现在我的所有身份验证逻辑再次正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-03
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 2011-07-12
    • 1970-01-01
    相关资源
    最近更新 更多