ruby-on-rails - 在设计中使用 Warden.authenticate 时无法更新参数

标签 ruby-on-rails authentication devise warden

我已将 Rails 从 3.2.8 升级到 Rails 4,还设计从 2.1.2 升级到 3.5.6,将 Warden 从 1.2.3 升级到 1.2.6。 我发现了一个问题,我不知道它应该属于 devise 或 warden。

在打电话之前

resource = warden.authenticate(:scope => resource_name, :recall =>"#{controller_path}#new")

我更新参数值如下:

params[:admin] = Hash.new 
params[:admin][:email] = params[:email] 
params[:admin][:password] = params[:password]

但是当我在 proxy.rb 中打印参数时,函数 defauthenticate(*args) params 仍然是原来的,里面没有任何 admin。

The issue is not happened when I use the old system.

这是我的部分代码和日志: Controller .rb

params[:admin] = Hash.new
params[:admin][:email] = params[:email]
params[:admin][:password] = params[:password]
params[:password] = '11111111111111'
# authenticate with warden
p '===================================='
p params
p warden
resource = warden.authenticate(:scope => resource_name, :recall => "#{controller_path}#new")
p params
p '===================================='

代理.rb

def authenticate(*args)
  p 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss'
  p params
  params[:password] = '111111111'
  p params
  p 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss'
  user, _opts = _perform_authentication(*args)
  user
end

日志:

"===================================="
{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bac9c3cedfc8fac2c2c2c294d9d5d7" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"11111111111111", "controller"=>"admin_sessions", "action"=>"create", "version"=>"v1", "format"=>"json", "admin"=>{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a09030e1f083a0202020254191517" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"xxxxxxxx"}}
Warden::Proxy:70145506030260 @config={:default_scope=>:admin, :scope_defaults=>{}, :default_strategies=>{:admin=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#Devise::Delegator:0x007f980f873e18}
"sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cebdb7baabbc8eb6b6b6b6e0ada1a3" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"xxxxxxxx", "controller"=>"admin_sessions", "action"=>"create", "version"=>"v1", "format"=>"json"}
{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ae9e3eeffe8dae2e2e2e2b4f9f5f7" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"111111111", "controller"=>"admin_sessions", "action"=>"create", "version"=>"v1", "format"=>"json"}
"sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
"sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="47343e332235073f3f3f3f6924282a" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"111111111", "controller"=>"admin_sessions", "action"=>"create", "version"=>"v1", "format"=>"json"}
"sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e5d575a4b5c6e56565656004d4143" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"11111111111111", "controller"=>"admin_sessions", "action"=>"create", "version"=>"v1", "format"=>"json", "admin"=>{"email"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3808a879681b38b8b8b8bdd909c9e" rel="noreferrer noopener nofollow">[email protected]</a>", "password"=>"xxxxxxxx"}}
"===================================="

好像有两个参数,一个在controller中,一个在warden中。

是否有任何配置或任何其他我错过的东西?

希望你的回答, 谢谢你。

最佳答案

当我在这里询问并回答类似的问题时没有看到这个问题 https://stackoverflow.com/a/40512141/208769

令人烦恼的是,您在 Controller 中看到的params似乎是rack维护的params的克隆,而不是对其的引用。而且由于 Warden 在中间件层拦截请求,因此它维护与请求参数的链接,并且对 Controller 的克隆一无所知。

简而言之,如果你想修改params并让warden看到你的修改,你需要修改request.params

关于ruby-on-rails - 在设计中使用 Warden.authenticate 时无法更新参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35727602/

相关文章:

ruby-on-rails - 带有 Remotipart 的 Rails AJAX 上传表单

php自动每日http登录请求

django - 在 VueJS 中存储身份验证 token 的最佳实践?

ruby-on-rails - Rails4.1,设计 3.2.4,rspec 功能,我如何获得 confirmation_token?

ruby-on-rails - 具有设计的表用户的自定义表名

css - SASS Compass 图像宽度和图像高度在 Rails 4 中不起作用

ruby-on-rails - 指定下个月的第一天?

ruby-on-rails - Ruby on Rails 3 时间 - 解析毫秒

authentication - 可以从自定义 LoginModule 访问远程 EJB 吗?

即使提交了表单,Jquery 绑定(bind)在 'ajax:success' 、 'ajax:error' 或 'ajax:complete' 上也不会执行