DiscourseConnect の一般的な問題のデバッグと修正

DiscourseConnect を使用しているフォーラムの管理者として、ユーザーがフォーラムへのログインを試みた際にエラーメッセージが表示されるという報告を時折受けることがあるかもしれません。例えば:「アカウントに問題があります。サイトの管理者にお問い合わせください。」

詳細な Discourse Connect ログの有効化

この問題をデバッグするには、まず Discourse のサイト設定で「詳細な Discourse Connect ログ記録」を有効にする必要があります。この設定が以前から有効になっていた場合は、直接 [Admin/Logs/Error Logs] に移動してください。設定が有効になっていなかった場合は、ユーザーに再度ログインを試みていただき、失敗したログインのログエントリを生成できるようにしてください。

ログエントリの読み取り

[Admin/Logs/Error Logs] に移動し、Verbose SSO log: Record was invalid で始まる最近のログエントリを探してください。エントリが見つからない場合は、ログページの下部にある検索ボックスに「Record was invalid」と入力してください。該当するログエントリをクリックし、ログツールバーの「info」タブをクリックします。

必要な情報は、ログエントリに記載された理由(reason)と、info セクションに記載された email および external_id です。

require_activation による DiscourseConnect ログイン問題の解決

SSO ログインでよくある問題の一つは、Record was invalid: User {:primary_email=>\"has already been taken\"} というエラーです。

これは、SSO ペイロード内の require_activation パラメータが true に設定されており、Discourse に既存のアカウントを持つユーザーが、まだ single_sign_on_record に関連付けられていないか、single_sign_on_record は存在するものの、そのレコードの external_id がログインしようとしているユーザーの external_id と一致していない場合に発生します。

これを確認するには、フォーラムの Rails コンソールにアクセスし、失敗した SSO ログインで使われたメールアドレスを持つユーザーを検索してください。

u = User.find_by_email('sally@example.com')

次に、このユーザーに single_sign_on_record があるか確認します。

sso_record = u.single_sign_on_record

ユーザーはフォーラムに存在するが SSO レコードを持っていない場合は、SSO ログから取得した値を使ってレコードを作成できます。

SingleSignOnRecord.create!(user_id: 2, external_id: 2, external_email: 'sally@example.com', last_payload: '')

これでユーザーはログインできるようになるはずです。

ユーザーに既存の SSO レコードがあるものの、その external_id が失敗したログイン試行の external_id と一致しない場合は、なぜこのような事態になったのか調査する必要があります。この問題は、ユーザーのアカウントが SSO プロバイダー側で削除され、その後再作成された場合に発生することがあります。この場合、SSO レコードを更新して新しい external_id を使用できます。

sso_record.external_id = <failed-sso-login-record-external_id>
sso_record.save!

これでユーザーはログインできるようになるはずです。

WP Discourse プラグインを使用しており、上記の問題に直面している場合は、Rails コンソールにアクセスせずに問題を解決する方法の詳細については、Validate Email Addresses with the WP Discourse plugin をご覧ください。

「いいね!」 17

I wasn’t sure how to enter the Rails console, but found the answer over here and thought I’d publish for anyone else who doesn’t know how to get into the Rails console.

  1. SSH into your site
  2. Login as root user then do the following:
  3. sudo -s
  4. cd /var/discourse/
  5. ls
  6. ./launcher enter app
  7. rails c

That should get you into the Rails console!

「いいね!」 3

I was doing this and it was not working, but I finally got it to work when I replaced this:

sso_record.external_id = <failed-sso-login-record-external_id>

with this:

sso_record.external_id = 91

Where “91” was the external_id of the user who was unable to login.

Thanks so much for this helpful discussion @simon! :raised_hands:

Yes, <failed-sso-login-record-external_id> is meant to be replaced with the external_id from the log entry.

「いいね!」 2

:man_facepalming: I was trying it with the " < > " and it wasn’t working, of course ツ

Is there an easy way to reset the SSO ties for specific accounts with the Rails console? I have a couple admin accounts that are tied to different WP accounts than I would like because originally the email addresses didn’t match properly. Can I manually set them to be tied to a different WP account?

You can find the user’s WordPress ID by going to their user page from the WordPress dashboard. The user’s ID will be displayed in the address bar of your browser as the value of the user_id query parameter.

Once you have the user’s WordPress ID, you can update their SSO record on Discourse following the steps outlined for updating the external_id at the end of the ‘Solving require_activation SSO login issues’ section of my original post. You need to be careful with this though - especially with admin accounts.

「いいね!」 3

こんにちは、これらの解決策を試してみましたが、何も機能しませんでした…外部 ID は同じで、SSO も有効になっています。他に解決策はありますか?困っています。

問題は特定のユーザーの SSO ログインにあるのか、それともあなたのサイト全体で SSO が全く機能していないのでしょうか?

特定のユーザーのみ対象

verbose sso logging サイト設定が有効になっていることを確認してください。設定済みの場合、ユーザーがログインを試みる際にサイトのログにエラーが見つかりますか?エラーログをここに共有いただければ、お手伝いできるかもしれません。ログに公開したくないデータが含まれている場合は、PM で送信してください。

「いいね!」 2

これで問題解決しましたか?必要な情報は揃っていますか?

これは、今回の状況に関係するメンバー(少なくともこの問題を報告した唯一のメンバー)のログの詳細です。

ありがとうございます!

「いいね!」 1

ありがとうございます、参考になりました。あなたの SSO プロバイダーサイトは WordPress サイトのようです。SSO には WP Discourse プラグインを使用していますか?もしそうであれば、かつプラグインの最新バージョンを使用している場合は、ユーザーのプロフィールページに移動し、「Email Address Verified」チェックボックスをオンにしてください。その後、「Save」ボタンをクリックすることを忘れないでください。これを行った後、ユーザーに再度ログインを試してもらってください。

WP Discourse プラグインを使用していない場合は、問題を解決するためのより詳細な手順をお伝えする必要があります。

「いいね!」 4

おっしゃる通りです。WordPress を使用しており、変更を行いました。ユーザーに再度お試しくださいと伝えてみます。本当にありがとうございます!! :smiley:

「いいね!」 1

成功しました!やったー!:smile: ありがとう!

「いいね!」 5