使用Devise和Omniauth的路由问题 [英] Problem with Routes using Devise and Omniauth

查看:110
本文介绍了使用Devise和Omniauth的路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让OAuth和Devise一起工作,但是我得到 Controller :: RoutingError(没有路由匹配/ users / auth / facebook / callback):尝试通过Facebook认证。

I am trying to get OAuth and Devise working together but I get Controller::RoutingError (No route matches "/users/auth/facebook/callback"): when trying to auth via Facebook.

奇怪的是,Google Apps不会发生这个问题。 (相同的回拨路线)。

Weirdly, the problem doesn't happen with Google Apps. (same callback route).

任何想法?

callback_controller:

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: p>

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

Why would the :provider => "facebook" trigger a RoutingError, but not :provider => "google_apps"?

推荐答案

发现:

在设计用户模型中,我有以下模块::omniauth_providers => [:facebook,,openid,:google_apps] 添加了(显然)没有做我以为这样做。我删除了该行,现在我的所有验证逻辑再次正常工作。

in the devise user model, i had the module: :omniauth_providers => [:facebook, :openid, :google_apps] added which (apparently) doesn't do what I thought it did. I removed the line and now all my auth logic works properly once again.

这篇关于使用Devise和Omniauth的路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆