DiscourseConnect 无法让我重新登录

我肯定是在按照这些说明安装 DiscourseConnect 时搞砸了。

幸运的是,说明中包含直接操作管理员设置的方法,但我需要的那个设置似乎已经变了?

说明中提到应设置 SiteSetting.enable_sso=false,但:

root@hestia-app:/var/www/discourse# rails c
[1] pry(main)> SiteSettings.enable_sso=false
NoMethodError: undefined method `enable_sso=' for SiteSettings:Module
from (pry):1:in `__pry__'
[2] pry(main)> 

有人知道新的管理员设置可能是什么吗?

谢谢!

1 个赞

啊,Discourse 很贴心地链接了 DiscourseConnect 的文章,于是:

cd /var/discourse
./launcher enter app
rails c
irb > SiteSetting.enable_discourse_connect = false
irb > SiteSetting.enable_local_logins = true
irb > exit
exit
1 个赞

太好了,你找到了这个问题。如果你在 WP Discourse 插件的选项页面中看到对 enable_sso 设置的引用,请注意这些引用应在插件的最新版本(2.3.0 版)中已更改为使用新的 enable_discourse_connect 设置名称。

如果 Meta 上该插件的文档中仍保留对旧设置名称的引用,我们需要将其更新为使用新的设置名称。我将在下周一初再次确认这一点。

请注意,在配置 DiscourseConnect 时,作为管理员,你可以通过访问你 Discourse 站点的 /u/admin-login 页面来绕过 SSO 登录。在该页面的表单中输入你的电子邮件地址,系统将会向你发送一封包含一次性登录链接的邮件。

1 个赞

哈哈

好吧……这确实让我看到了登录页面,但一旦登录,系统就会把我登出,并再次重定向到登录页面。

使用 /u/admin-login 方法时,也会出现登出并重定向的情况。我是否应该设置或取消设置其他值?

——补充——

有没有办法通过 rails c 命令行来验证管理员设置值?

1 个赞

在 Discourse 上,您需要以下设置:

  • enable_discourse_connect
  • discourse_connect_url(应设置为您的 WordPress 站点主页)
  • discourse_connect_secret(请确保其值与您在 WordPress 站点的 DiscourseConnect 密钥设置中输入的值一致)

您可能还应该在 Discourse 上启用 verbose_discourse_connect_logging 站点设置。启用该设置后,您可能会在 Discourse 错误日志中获得有关问题原因的一些有用详细信息。

在 WordPress 上,请确保您已填写 DiscourseConnect 密钥设置。WordPress 上唯一需要启用的其他设置是“启用 DiscourseConnect 提供者”设置。

1 个赞

@simon 非常感谢你提供的 verbose_discourse_connect_logging 提示!

好的,现在 enable_discourse_connectfalse,而 enable_local_loginstrue

也许有人知道这里发生了什么?

让我们点击管理员登录邮件链接

Started GET "/session/email-login/5356b2413338852f25d4382e34fb53a6" for {my.ip.address} at 2021-08-07 02:33:43 +0000
Processing by SessionController#email_login_info as HTML
  Parameters: {"token"=>"5356b2413338852f25d4382e34fb53a6"}
  Rendered default/empty.html.erb within layouts/application (Duration: 0.1ms | Allocations: 11)
  Rendered layout layouts/application.html.erb (Duration: 41.1ms | Allocations: 8102)
Completed 200 OK in 66ms (Views: 43.4ms | ActiveRecord: 0.0ms | Allocations: 12210)
Started GET "/session/email-login/5356b2413338852f25d4382e34fb53a6.json" for {my.ip.address} at 2021-08-07 02:33:48 +0000
Processing by SessionController#email_login_info as JSON
  Parameters: {"token"=>"5356b2413338852f25d4382e34fb53a6"}
Completed 200 OK in 25ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 4548)

好的,让我们点击 Discourse 安装页面上的登录链接

Started GET "/session/csrf" for {my.ip.address} at 2021-08-07 02:33:56 +0000
Processing by SessionController#csrf as JSON
Completed 200 OK in 2ms (Views: 0.3ms | Allocations: 308)

Started POST "/session/email-login/5356b2413338852f25d4382e34fb53a6" for {my.ip.address} at 2021-08-07 02:33:57 +0000
Processing by SessionController#email_login as */*
  Parameters: {"second_factor_method"=>"1", "timezone"=>"America/Denver", "token"=>"5356b2413338852f25d4382e34fb53a6"}
Completed 200 OK in 231ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 24272)

这里出了点问题

Started GET "/" for {my.ip.address} at 2021-08-07 02:33:58 +0000
Processing by ListController#latest as HTML
Redirected to http://my.discourse.install/login
Filter chain halted as :redirect_to_login_if_required rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.0ms | Allocations: 613)

现在只是渲染登录页面,它确实正常工作了;)

Started GET "/login" for {my.ip.address} at 2021-08-07 02:33:59 +0000
Processing by StaticController#show as HTML
  Parameters: {"id"=>"login"}
  Rendered static/login.html.erb within layouts/application (Duration: 38.2ms | Allocations: 1520)
  Rendered layout layouts/application.html.erb (Duration: 103.4ms | Allocations: 12203)
Completed 200 OK in 130ms (Views: 105.7ms | ActiveRecord: 0.0ms | Allocations: 16261)
Started GET "/login.html" for {my.ip.address} at 2021-08-07 02:34:04 +0000
Processing by StaticController#show as HTML
  Parameters: {"id"=>"login"}
  Rendered static/login.html.erb (Duration: 22.0ms | Allocations: 1352)
Completed 200 OK in 25ms (Views: 23.0ms | Allocations: 1970)
1 个赞

另外,有人知道在 $rails c 命令行中是否有命令可以导出所有管理员设置/值对?我想我可以重置所有 DiscourseConnect 相关设置并重新开始。或者,也许有一个 CLI 命令可以直接将所有管理员设置重置为初始状态?

— 补充编辑 —

哈哈,我刚发现了 SiteSetting.all,这简直是把信息全 dump 出来了。它有过滤功能吗?

— 补充编辑 —

在另一个帖子中发现了这个小技巧:

puts SiteSetting.all.map {|s| "#{s.name}: #{s.value}" }.join "\n"

……然后我重置了所有与 DiscourseConnect 相关的设置。但仍然遇到奇怪的登录重定向问题。

enable_bookmarks_with_reminders: t
meta_category_id: 2
staff_category_id: 3
lounge_category_id: 4
default_theme_id: 1
tos_topic_id: 4
guidelines_topic_id: 5
privacy_topic_id: 6
welcome_topic_id: 7
lounge_welcome_topic_id: 8
admin_quick_start_topic_id: 9
push_api_secret_key: {已隐藏}
send_welcome_message: f
has_login_hint: f
global_notice: 
default_trust_level: 1
default_email_digest_frequency: 1440
bootstrap_mode_enabled: t
title: {已隐藏}
site_description: {已隐藏}
short_site_description: {已隐藏}
login_required: t
must_approve_users: t
contact_email: {已隐藏}
contact_url: {已隐藏}
site_contact_username: system
company_name: {已隐藏}
base_font: oxanium
heading_font: system
logo: 3
logo_small: 4
force_https: t
allow_user_locale: t
categories_topics: 25
suggested_topics: 7
share_links: email
share_quote_buttons: email
default_dark_mode_color_scheme_id: 1
topics_per_period_in_top_summary: 25
unicode_usernames: f
enable_names: f
enable_user_directory: f
allow_anonymous_posting: t
anonymous_posting_min_trust_level: 0
allow_uncategorized_topics: f
show_copy_button_on_codeblocks: t
max_image_megapixels: 150
max_image_size_kb: 10000
max_attachment_size_kb: 10000
clean_up_uploads: t
external_system_avatars_enabled: f
vapid_public_key: {已隐藏}
vapid_private_key: {已隐藏}
vapid_public_key_bytes: {已隐藏}
vapid_base_url: {已隐藏}
enable_local_logins: t
enable_discourse_connect: f
pop3_polling_username: {已隐藏}
enable_discourse_connect_provider: f
discourse_connect_allows_all_return_paths: f
discourse_connect_url: 
discourse_connect_secret: 
1 个赞

所以我尝试添加一个新账户,却收到以下错误信息:

我们无法检测到您的账户是否已创建,请确保已启用 Cookie。

什么?难道我应该重新安装吗???

—编辑补充—

我确实收到了注册验证邮件,验证成功了。但当我尝试以新用户身份登录时,却收到:

管理员必须手动批准您的新账户后,您才能访问此论坛。账户获批后您将收到一封邮件!

哈哈……:facepalm:

—编辑补充—

只是想说明一下,我确实喜欢 Discourse 的复杂性。它是一款出色的软件。唯一能与之相提并论的论坛是 XF。多年前,当 [unknown] 还是 SimpleMachines 的主要开发者时,那也是一个非常棒的产品,但那个时代早已过去。感谢所有开发者。你们打造出了一台卓越而优雅的机器。

1 个赞

真正的错误似乎是 无法验证 CSRF 令牌真实性。答案就在这个帖子中:Can't Login to Discourse - CSRF Token Authenticity

我在 apache2.conf 文件中添加了以下内容:

RequestHeader set X-Forwarded-Proto https

错误日志如下:

Started POST "/session" for {my.ip} at 2021-08-07 11:45:54 +0000
Processing by SessionController#create as */*
  Parameters: {"login"=>"{me}", "password"=>"[FILTERED]", "second_factor_method"=>"1", "timezone"=>"America/Denver"}
Can't verify CSRF token authenticity.
  Rendered text template (Duration: 0.0ms | Allocations: 1)
Filter chain halted as :verify_authenticity_token rendered or redirected
Completed 403 Forbidden in 13ms (Views: 1.5ms | ActiveRecord: 0.0ms | Allocations: 898)
2 个赞

很高兴你找到了原因。我很好奇,你是如何部署 Discourse 的?我猜你并没有使用标准的 Docker 安装方式?

我已更新了 Install and configure the WP Discourse Wordpress plugin for Discourse 中的相关引用 :+1:

3 个赞

我确实使用了 Docker,但我在其前面配置了 Apache2 作为反向代理,以便将其作为虚拟主机运行在 Hestia 控制面板之后。我当初配置 Hestia 时使用的是 Apache2 而非 Nginx……这就是为什么我使用了 Apache2。

如果你查看这个讨论的末尾,就能看到我的具体配置。

2 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.