管理员用户的活动管理员登录仅在本地主机上的Chrome中使用正确的凭据重定向回到登录页面 [英] Active Admin login for admin users redirects back to the login page with correct credentials only in Chrome on localhost

查看:59
本文介绍了管理员用户的活动管理员登录仅在本地主机上的Chrome中使用正确的凭据重定向回到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在Chrome中本地遇到此问题,而在生产环境中却没有。在Safari或Firefox中也不是问题。我不确定是什么引起了该问题,因为我最近的更改是添加Redis / Sidekiq来异步处理作业,这似乎并不相关。

I am only having this problem locally in Chrome, not in production. It is also not a problem in Safari or Firefox. I am not sure what caused the problem as my only recent change was adding Redis/Sidekiq for asynchronously handling jobs, which doesn't seem relevant.

我在Chrome,它仍然没有帮助。

I cleared my cookies in Chrome and it still did not help.

问题是在我重置本地数据库并加载我的种子和示例数据之后开始的。我使用psql查看数据库中的数据,并可以确认我具有正确的用户和管理员用户,以便能够通过Active Admin登录页面进行身份验证。

The problem started after I reset the local database and loaded in my seeds and example data. I used psql to look at the data in the database and can confirm that I have the correct users and admin users in place to be able to authenticate through the Active Admin sign in page.

当我使用不正确的凭据时,会得到相应的无效的电子邮件或密码。 Active Admin中出现此消息,这是预期的,我会在终端中看到预期的输出: Completed 401 Unauthorized等。

When I use incorrect credentials I get the appropriate "Invalid Email or password." message in Active Admin, which is expected, and I see the expected output in terminal: "Completed 401 Unauthorized" etc.

当我使用正确的凭据时,我遇到了问题。我被重定向回同一页面(看起来页面刚刚刷新)。

When I use the correct credentials I have the problem. I get redirected back to the same page (it looks like the page just refreshes).

在终端中,我可以看到302和重定向到未经身份验证的管理页面(不知道为什么),这导致我重定向回

In the terminal I can see a 302 and a redirect to the admin page where I am not authenticated (don't know why), which is causing me to redirect back to the log in page.

在Chrome中登录失败的终端输出:

Terminal output for failing login attempt in Chrome:

Incoming Headers:
  Origin: http://localhost:3000
  Path-Info: /admin/login
  Access-Control-Request-Method: 
  Access-Control-Request-Headers: 
Started POST "/admin/login" for ::1 at 2020-03-14 01:15:49 -0500
Processing by ActiveAdmin::Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Qirj5VE07/Xv2c3vrwNzmNH3pIfrd615p+OnaXV8cSWVeeIaEBIWRAK8tsquti5KgqmJv/sgmGD84VQCxkmKdg==", "admin_user"=>{"email"=>"mishaherscu@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Login"}
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  AdminUser Load (0.3ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."email" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["email", "mishaherscu@gmail.com"], ["LIMIT", 1]]
Redirected to http://localhost:3000/admin
Completed 302 Found in 121ms (ActiveRecord: 0.5ms | Allocations: 3418)


::1 - - [14/Mar/2020:01:15:49 CDT] "POST /admin/login HTTP/1.1" 302 93
http://localhost:3000/admin/login -> /admin/login
Started GET "/admin" for ::1 at 2020-03-14 01:15:49 -0500
Processing by Admin::DashboardController#index as HTML
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
Completed 401 Unauthorized in 2ms (ActiveRecord: 0.2ms | Allocations: 611)


::1 - - [14/Mar/2020:01:15:49 CDT] "GET /admin HTTP/1.1" 302 99
http://localhost:3000/admin/login -> /admin
Started GET "/admin/login" for ::1 at 2020-03-14 01:15:49 -0500
Processing by ActiveAdmin::Devise::SessionsController#new as HTML
  AdminUser Load (0.7ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/devise/sessions/new.html.erb within layouts/active_admin_logged_out
  Rendered /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/devise/shared/_links.erb (Duration: 0.2ms | Allocations: 93)
  Rendered /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/devise/sessions/new.html.erb within layouts/active_admin_logged_out (Duration: 7.5ms | Allocations: 6691)
Completed 200 OK in 34ms (Views: 31.0ms | ActiveRecord: 0.7ms | Allocations: 30877)

在Safari中成功登录的终端输出:

Terminal output for successful login attempt in Safari:

Incoming Headers:
  Origin: http://localhost:3000
  Path-Info: /admin/login
  Access-Control-Request-Method: 
  Access-Control-Request-Headers: 
Started POST "/admin/login" for ::1 at 2020-03-14 14:05:32 -0500
Processing by ActiveAdmin::Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Zr9FK5J4+tc+/a/RY4ir84YWi/MkIfnTRzAj3sg5yrqb7o8yuIggXu+mT273TN1xzNCFH9EYP2DVYZMte2JUEw==", "admin_user"=>{"email"=>"mishaherscu@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Login"}
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."email" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["email", "mishaherscu@gmail.com"], ["LIMIT", 1]]
   (0.2ms)  BEGIN
  AdminUser Update (0.2ms)  UPDATE "admin_users" SET "remember_created_at" = $1, "updated_at" = $2 WHERE "admin_users"."id" = $3  [["remember_created_at", "2020-03-14 19:05:32.213581"], ["updated_at", "2020-03-14 19:05:32.213742"], ["id", 1]]
   (0.9ms)  COMMIT
Redirected to http://localhost:3000/admin
Completed 302 Found in 101ms (ActiveRecord: 1.4ms | Allocations: 1308)


::1 - - [14/Mar/2020:14:05:32 CDT] "POST /admin/login HTTP/1.1" 302 93
http://localhost:3000/admin/login -> /admin/login
Incoming Headers:
  Origin: http://localhost:3000
  Path-Info: /admin
  Access-Control-Request-Method: 
  Access-Control-Request-Headers: 
Started GET "/admin" for ::1 at 2020-03-14 14:05:32 -0500
Processing by Admin::DashboardController#index as HTML
  AdminUser Load (0.1ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/page/index.html.arb
  Rendered /Users/mishaherscu/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activeadmin-2.6.1/app/views/active_admin/page/index.html.arb (Duration: 25.0ms | Allocations: 32977)
Completed 200 OK in 26ms (Views: 25.4ms | ActiveRecord: 0.1ms | Allocations: 33501)


::1 - - [14/Mar/2020:14:05:32 CDT] "GET /admin HTTP/1.1" 200 5255
http://localhost:3000/admin/login -> /admin

从routes.rb:

From routes.rb:

devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

有人对导致它的原因和/或如何解决有任何想法吗?如果有任何缺失,也很乐意提供其他信息。

Does anyone have any ideas about what is causing it and/or how it could be fixed? Also happy to provide additional information if anything is missing.

推荐答案

这最终成功了,并且有很多麻烦:

This ended up working, with a bunch of finagling:

https://github.com/codica2/rails-puma-ssl

我现在正在使用类似的方法在本地主机上启动Rails:
rails s -b'ssl:// localhost:3000?key = server.key& cert = server .crt'

I am now using something like this to launch rails on localhost: rails s -b 'ssl://localhost:3000?key=server.key&cert=server.crt'

/ etc / hosts 中,我不得不更改 127.0.0.1 localhost 127.0.0.1 localhost.ssl

In /etc/hosts, I had to change 127.0.0.1 localhost to 127.0.0.1 localhost.ssl

要查看本地主机,我必须添加 s,例如,Active Admin在此处: https:// localhost:3000 / admin

To see localhost, I have to add the "s" so, for example, Active Admin is here: https://localhost:3000/admin

这篇关于管理员用户的活动管理员登录仅在本地主机上的Chrome中使用正确的凭据重定向回到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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