Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails &引用;没有找到。认证通过”;错误。设计全授权模块';当它';它在另一个引擎里_Ruby On Rails_Ruby_Devise_Rubygems_Omniauth - Fatal编程技术网

Ruby on rails &引用;没有找到。认证通过”;错误。设计全授权模块';当它';它在另一个引擎里

Ruby on rails &引用;没有找到。认证通过”;错误。设计全授权模块';当它';它在另一个引擎里,ruby-on-rails,ruby,devise,rubygems,omniauth,Ruby On Rails,Ruby,Devise,Rubygems,Omniauth,我尝试将Desive放入另一块可安装的宝石中,同时遵循以下指南: 除了omniauth部分外,一切似乎都很好。我正试着去上班。我发现了这一点,但除了建议的解决方案都不起作用之外,我还注意到该问题中提到的解决方案 以下是我迄今为止所做的工作: 我的引擎/my\u引擎.gemspec s.add_dependency 'omniauth' s.add_dependency 'devise' s.add_dependency 'omniauth-google-oauth2' my\u engine

我尝试将Desive放入另一块可安装的宝石中,同时遵循以下指南:

除了omniauth部分外,一切似乎都很好。我正试着去上班。我发现了这一点,但除了建议的解决方案都不起作用之外,我还注意到该问题中提到的解决方案

以下是我迄今为止所做的工作:

我的引擎/my\u引擎.gemspec

s.add_dependency 'omniauth'
s.add_dependency 'devise'
s.add_dependency 'omniauth-google-oauth2'
my\u engine/lib/my\u engine.rb

require 'omniauth-google-oauth2'
require 'devise'
config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH2_API_KEY'], ENV['GOOGLE_OAUTH2_SECRET'], scope: 'email, profile'
devise_for :users, controllers: {omniauth_callbacks: 'my_engine/omniauth_callbacks'}, class_name: "MyEngine::User", module: :devise
class MyEngine::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    auth = request.env["omniauth.auth"]
    user = MyEngine::User.from_omniauth(request.env["omniauth.auth"])
    user.update_attributes(name: auth.info.name)
    if user.persisted?
      flash.notice = 'Signed in!'
      sign_in_and_redirect user
    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end
  end
  alias_method :google_oauth2, :all
end
my_engine/config/initializers/designe.rb

require 'omniauth-google-oauth2'
require 'devise'
config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH2_API_KEY'], ENV['GOOGLE_OAUTH2_SECRET'], scope: 'email, profile'
devise_for :users, controllers: {omniauth_callbacks: 'my_engine/omniauth_callbacks'}, class_name: "MyEngine::User", module: :devise
class MyEngine::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    auth = request.env["omniauth.auth"]
    user = MyEngine::User.from_omniauth(request.env["omniauth.auth"])
    user.update_attributes(name: auth.info.name)
    if user.persisted?
      flash.notice = 'Signed in!'
      sign_in_and_redirect user
    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end
  end
  alias_method :google_oauth2, :all
end
我的引擎/config/routes.rb

require 'omniauth-google-oauth2'
require 'devise'
config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH2_API_KEY'], ENV['GOOGLE_OAUTH2_SECRET'], scope: 'email, profile'
devise_for :users, controllers: {omniauth_callbacks: 'my_engine/omniauth_callbacks'}, class_name: "MyEngine::User", module: :devise
class MyEngine::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    auth = request.env["omniauth.auth"]
    user = MyEngine::User.from_omniauth(request.env["omniauth.auth"])
    user.update_attributes(name: auth.info.name)
    if user.persisted?
      flash.notice = 'Signed in!'
      sign_in_and_redirect user
    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end
  end
  alias_method :google_oauth2, :all
end
my\u engine/app/controllers/my\u engine/omniauth\u callbacks\u controller.rb

require 'omniauth-google-oauth2'
require 'devise'
config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH2_API_KEY'], ENV['GOOGLE_OAUTH2_SECRET'], scope: 'email, profile'
devise_for :users, controllers: {omniauth_callbacks: 'my_engine/omniauth_callbacks'}, class_name: "MyEngine::User", module: :devise
class MyEngine::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    auth = request.env["omniauth.auth"]
    user = MyEngine::User.from_omniauth(request.env["omniauth.auth"])
    user.update_attributes(name: auth.info.name)
    if user.persisted?
      flash.notice = 'Signed in!'
      sign_in_and_redirect user
    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end
  end
  alias_method :google_oauth2, :all
end
class MyEngine::OmniAuthCallbackController

当我单击“使用Google OAuth2登录”时,它直接进入MyEngine::OmniAuthCallbackController#passthru
,并输出“未找到.身份验证passthru”。我一直在挖掘源代码,但我不知道Deave如何让它通过provider方法而不是
#passthru
。我是不是遗漏了什么?我在rails 4.1、Ruby 2.0、Desive 3.2.4和omniauth-oauth2 1.2.0上运行。

我也遇到了这个问题。我使用的版本与您链接到的github问题页面上讨论的解决方案非常相似,但不完全相同(我在下面的代码中稍微调整了一下,因为我的
设计中为
指定了一个自定义的
:path
)。此外,我目前正在使用Desive 3.1.2,但希望它足够类似,以便下面的内容能够为您工作

在我的引擎/config/routes.rb中:

devise_for :users, :class_name => 'MyEngine::User', :module => :devise, :controllers => { :omniauth_callbacks => "my_engine/omniauth_callbacks" }

devise_scope :user do
  # Had to add routes for callbacks here because otherwise the routes get
  # messed up -- prepending an extra "/my_engine" in one case.
  providers = Regexp.union(Devise.omniauth_providers.map(&:to_s))

  path_prefix = '/users/auth'

  match "#{path_prefix}/:provider",
    :constraints => { :provider => providers },
    :to => "omniauth_callbacks#passthru",
    :as => :user_omniauth_authorize,
    :via => [:get, :post]

  match "#{path_prefix}/:action/callback",
    :constraints => { :action => providers },
    :to => 'omniauth_callbacks',
    :as => :user_omniauth_callback,
    :via => [:get, :post]
end
config.router_name = :my_engine
config.omniauth_path_prefix = "/my_engine/users/auth"
在my_engine/config/initializers/designe.rb中:

devise_for :users, :class_name => 'MyEngine::User', :module => :devise, :controllers => { :omniauth_callbacks => "my_engine/omniauth_callbacks" }

devise_scope :user do
  # Had to add routes for callbacks here because otherwise the routes get
  # messed up -- prepending an extra "/my_engine" in one case.
  providers = Regexp.union(Devise.omniauth_providers.map(&:to_s))

  path_prefix = '/users/auth'

  match "#{path_prefix}/:provider",
    :constraints => { :provider => providers },
    :to => "omniauth_callbacks#passthru",
    :as => :user_omniauth_authorize,
    :via => [:get, :post]

  match "#{path_prefix}/:action/callback",
    :constraints => { :action => providers },
    :to => 'omniauth_callbacks',
    :as => :user_omniauth_callback,
    :via => [:get, :post]
end
config.router_name = :my_engine
config.omniauth_path_prefix = "/my_engine/users/auth"

其中一些可能是不必要的,但我花了一些时间使用调试器逐步完成流程后,它就这样工作了,从那时起,我就没有时间回去尝试使它更优雅/精简或任何东西。

我找到了一个更好的解决方案。更新lib/MyEngine/engine.rb。 使用此解决方案,您不必添加Desive scope部分(我的示例仅适用于facebook)

模块MyEngine
需要“omniauth”
需要“omniauth facebook”
类引擎<::Rails::引擎
隔离名称空间SimpleUser
中间件。使用OmniAuth::Builder do
提供者:facebook,ENV['facebook\u KEY',ENV['facebook\u SECRET',:scope=>ENV['facebook\u scope']
结束
结束

我知道这听起来不是一个完整或完美的解决方案,但您能否向控制器添加一个passthru操作并处理其中的特定于提供商的代码?此外,您能否向我们展示Desive/omniauth相关路径的rake路由结果?我得到了一个
无效的路由名称,已在使用:“user\u omniauth\u Authority”
错误,因为Desive已创建路由。你是怎么解决那个问题的?我没有犯那个错误!我认为这是因为我仍然使用Rails3.2.19,我认为检查是作为Rails4的一部分添加的。将
skip::omniauth_回调
添加到您的
designe_for
语句中应该会停止尝试的复制,因为它会阻止designe生成这些路由。我尝试将
skip::omniauth_回调
添加到我的
designe_for
中,我的fb登录流停止工作!我必须在my
my\u engine\initializers\designe.rb的最后一个
end
之前添加
Rails.application.config.after\initializer::do::OmniAuth::config.path\prefix=config.OmniAuth\u path\u prefix=“/my\u engine/u/auth”end
。如果这对你有效,我会更新我的答案。我仍然得到相同的
未找到。身份验证通过。
错误。您是否覆盖了OmniAuthCallbackController#passthru
?因为我没有@TerencePonce,你最终解决了这个问题吗?我真的很感兴趣。这不会在
路线中没有更改的情况下生成任何引擎路线。rb
对我来说