Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.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 凌驾/“身份验证”-omniauth标识页_Ruby On Rails_Rack_Omniauth - Fatal编程技术网

Ruby on rails 凌驾/“身份验证”-omniauth标识页

Ruby on rails 凌驾/“身份验证”-omniauth标识页,ruby-on-rails,rack,omniauth,Ruby On Rails,Rack,Omniauth,我使用omniauth而不使用Desive进行身份验证,因为我喜欢它的简单性。除了omniauth facebook,我还使用omniauth身份提供电子邮件/pw身份验证。 介绍如何设置自定义的注册和登录页面。但是identity(/auth/identity和/auth/identity/register)提供的默认路由仍然可以访问 我想让这些在我的控制下,因为我只想让受邀用户注册。有没有办法覆盖机架中间件提供的路由? 试图 match "/auth/identity", to: "some

我使用omniauth而不使用Desive进行身份验证,因为我喜欢它的简单性。除了omniauth facebook,我还使用omniauth身份提供电子邮件/pw身份验证。
介绍如何设置自定义的注册和登录页面。但是identity(/auth/identity和/auth/identity/register)提供的默认路由仍然可以访问

我想让这些在我的控制下,因为我只想让受邀用户注册。有没有办法覆盖机架中间件提供的路由?
试图

match "/auth/identity", to: "somewhere#else"
这可不行

是否有关闭这些默认路由的配置?文档中没有给出任何关于此的详细信息

不幸的是,我是个新手,所以我还没有足够的洞察力来独自解决这个问题

如果有人能给我指出正确的方向,我会很高兴的

一个
OmniAuth
策略对象有一个方法
request\u-phase
,它生成一个html表单并向用户显示。对于“omniauth标识”策略,这将是您在
/auth/identity
url上看到的表单

您可以覆盖
请求\u阶段
方法,并将表单生成器替换为重定向到自定义登录页面(假设您在
/login
url上有该页面)。将以下内容与omniauth初始化代码放在一起:

module OmniAuth
  module Strategies
   class Identity
     def request_phase
       redirect '/login'
     end
   end
 end
end

# Your OmniAuth::Builder configuration goes here...

除1gors和iains外,回答:

“/auth/identity/register”也与GET一起提供,要覆盖,我必须:

class OmniAuth::Strategies::Identity
  alias :original_other_phase :other_phase
  def other_phase
    if on_registration_path? && request.get?
      redirect '/sign_up'
    else
      original_other_phase
    end
  end
end

您可以在omniauth.rb中设置方法

:on_login => SessionsController.action(:new)
例如:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :identity,
           :fields => [:nickname],
           :on_login => SessionsController.action(:new),
           :on_registration => UsersController.action(:new),
           :on_failed_registration => SessionsController.action(:registration_failure)
end

最后,我给了受邀请的用户一个密码短语,所以这并不重要,原来的身份站点仍然可以访问……如果你想覆盖请求阶段,那么你可能也会对注册阶段做同样的操作,为了确保未设置
注册路径
选项,+1我将其添加到
/config/initializers/omniauth.rb
下的
Rails.application.config.middleware.use omniauth::Builder do。。。结束
block和@1gors应答。谢谢:o)