【发布时间】: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 => "facebook" 会触发 RoutingError,而不是:provider => "google_apps"?
【问题讨论】:
-
是您在
app/controllers/users/omniauth_callbacks_controller.rb?中的文件 -
是的!就像我说的 - 谷歌的工作正常 - 它只是在使用 Facebook 时。
标签: ruby-on-rails routes devise omniauth