偶尔,用户在尝试登录时会遇到每次都被要求设置新 Discourse 账户的问题。这种情况通常发生在以下两种场景:一是旧账户现在重新登录 Discourse;二是用户原本使用用户名和密码注册,现在却尝试通过 OAuth 登录。过去,解决此问题的方法是在 Discourse 实例的 Rails 控制台中运行以下命令,将他们的 Auth0 OAuth2 凭据与 Discourse 中的用户 ID 关联:
PluginStore.set('oauth2_basic', 'oauth2_basic_user_google-apps|tony.danza@aol.com', {"user_id":7235})
但问题似乎是该操作不再生效,实际上它返回的是 =>True,而以前会返回 Ok。我现在处于 Pry 提示符下,而过去我认为并非如此。当我退出 Pry 时,它也会将我带出 Rails 控制台。
请问这可能是什么原因?谢谢!
使用的插件:GitHub - discourse/discourse-oauth2-basic: A basic OAuth2 plugin for use with Discourse · GitHub
Falco
(Falco)
2019 年9 月 4 日 17:35
2
That command is outdated, now the plugin uses the user associations table.
1 个赞
Can you share an example of the command that I will now run @Falco in replacement of it? Thank you for you help
Following up for the latest command @Falco , thanks!
Any update or insight on the command @Falco ?
Falco
(Falco)
2019 年9 月 11 日 14:12
6
This file shound give you an idea of how to construct the command you need:
# frozen_string_literal: true
class MoveToManagedAuthenticator < ActiveRecord::Migration[5.2]
def up
execute <<~SQL
INSERT INTO user_associated_accounts (
provider_name,
provider_uid,
user_id,
created_at,
updated_at
) SELECT
'oauth2_basic',
replace(key, 'oauth2_basic_user_', ''),
(value::json->>'user_id')::integer,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
FROM plugin_store_rows
WHERE plugin_name = 'oauth2_basic'
AND value::json->>'user_id' ~ '^[0-9]+$'
This file has been truncated. show original
1 个赞
Sorry for the delay, I had to upgrade discourse before I tried again. I gave the change a shot but didn’t experience success. Below is the example of what I have since tried that return true.
[1] pry(main)> PluginStore.set('oauth2_basic', 'user_associated_accounts_google-apps|tony.danza@gmail.com', {"user_id":1234})
=> true
Following up on this topic, thanks for the help!
Falco
(Falco)
2019 年9 月 30 日 21:37
14
Damn you pinged me 7 times while I was on vacation…
Instead of using the PluginStore.set method, you need to create a new UserAssociatedAccount, like for example:
UserAssociatedAccount.create!(provider_name: 'oauth2_basic', provider_uid: 'google-apps|tony.danza@aol.com', user_id: 7235)
Sorry about that @Falco , we too have had a hard time when having Community members go on vacation and not being able to keep everyone in the loop. I hope you had a great vacation and I apologize.
I will give your suggestion a go tomorrow and share the results. Thank you again for your help
嘿,@Falco ,跟进一下这件事。当我尝试运行上面建议的命令时,收到以下信息:
root@ip-172-31-20-121-app:/var/www/discourse# rails c
NOTE: 继承 Faraday::Error::ClientError 已弃用;请使用 Faraday::ClientError。它将在 1.0 版本或之后被移除。
Faraday::Error::ClientError.inherited 调用自 /var/www/discourse/plugins/discourse-github/gems/2.6.5/gems/octokit-4.14.0/lib/octokit/middleware/follow_redirects.rb:14。
[1] pry(main)> UserAssociatedAccount.create!(provider_name: 'oauth2_basic', provider_uid: 'google-apps|nico@auth0.com', user_id: 1722)
ActiveRecord::RecordNotUnique: PG::UniqueViolation: 错误:重复键值违反了唯一约束 "associated_accounts_provider_uid"
详情:键 (provider_name, provider_uid)=(oauth2_basic, google-apps|nico@auth0.com) 已存在。
来自 /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.1.3/lib/patches/db/pg.rb:69:in `async_exec_params'
由 PG::UniqueViolation 引起:错误:重复键值违反了唯一约束 "associated_accounts_provider_uid"
详情:键 (provider_name, provider_uid)=(oauth2_basic, google-apps|nico@auth0.com) 已存在。
来自 /var/www/discours