我正在尝试让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
中? - David