Ash*_*Ash 4 routes ruby-on-rails devise omniauth
我试图让OAuth和Devise一起工作,但是Controller::RoutingError (No route matches "/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
Run Code Online (Sandbox Code Playgroud)
routes.rb中:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
Run Code Online (Sandbox Code Playgroud)
为什么会:provider => "facebook"触发RoutingError,但不是:provider => "google_apps"?
找到了:
在设计用户模型中,我有一个模块::omniauth_providers => [:facebook, :openid, :google_apps]添加了(显然)没有做我认为它做的事情.我删除了该行,现在我的所有auth逻辑再次正常工作.
| 归档时间: |
|
| 查看次数: |
6174 次 |
| 最近记录: |