تصحيح الأخطاء وإصلاح مشكلات DiscourseConnect الشائعة

بصفتك مديرًا لمنصة منتديات تستخدم DiscourseConnect، قد تتلقى أحيانًا تقارير من مستخدمين يحاولون تسجيل الدخول إلى المنتدى فيظهر لهم رسالة خطأ. على سبيل المثال: “هناك مشكلة في حسابك. يرجى التواصل مع مدير الموقع.”

تمكين سجلات Discourse Connect التفصيلية

لحل المشكلة، الخطوة الأولى هي تمكين إعداد الموقع المسمى “verbose discourse connect logging” في نظام Discourse. إذا كان هذا الإعداد مفعلًا مسبقًا، يمكنك الانتقال مباشرة إلى سجلات موقعك عبر Admin/Logs/Error Logs. أما إذا لم يكن الإعداد مفعلًا مسبقًا، فستحتاج إلى طلب من المستخدم محاولة تسجيل الدخول مرة أخرى لتوليد مدخل سجل لمحاولته الفاشلة في تسجيل الدخول.

قراءة مدخل السجل

انتقل إلى Admin/Logs/Error Logs وابحث عن مدخل سجل حديث يبدأ بـ Verbose SSO log: Record was invalid. إذا واجهت صعوبة في العثور على المدخل، أدخل عبارة ‘Record was invalid’ في مربع البحث الموجود في أسفل صفحة السجلات. انقر على مدخل السجل، ثم انقر على تبويب ‘info’ في شريط أدوات السجلات:

المعلومات التي ستحتاجها هي السبب (المذكور في مدخل السجل)، بالإضافة إلى email و external_id (الموجودة في قسم المعلومات).

حل مشكلات تسجيل الدخول عبر DiscourseConnect المتعلقة بـ require_activation

مشكلة شائعة في تسجيل الدخول عبر SSO هي: Record was invalid: User {:primary_email=\u003e\"has already been taken\"}.

قد يحدث هذا عندما يكون معامل require_activation في حمولة SSO مضبوطًا على 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 وتواجه المشكلة المذكورة أعلاه، فراجع Validate Email Addresses with the WP Discourse plugin للحصول على تفاصيل حول كيفية حل المشكلة دون الحاجة إلى الوصول إلى وحدة تحكم Rails.

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 إعجابات

Hi, we tried these solutions but nothing worked… External id were the same and SSO is active. Do you have other solution please? I’m lost :frowning:

Is the problem with SSO login for a particular user, or is SSO not working at all on your site?

only for a particular user

Make sure you have enabled the verbose sso logging site setting. If you have done that, are you able to find the error in your site’s logs when the user attempts to login? If you can share the error log here, we may be able to help. If there is data in the log that you don’t want to make public, you can send it to me in a PM.

إعجابَين (2)

Does this help you? It is what you need?

It is the detail of the Log for member concerned by the situation (or at least, the only one that reported this problem)

Thank you so much!

إعجاب واحد (1)

Thanks, that helps. It looks like your SSO provider site is a WordPress site. Are you using the WP Discourse plugin for SSO? If so, and you are using the latest version of the plugin, try going to the user’s profile page and checking the ‘Email Address Verified’ checkbox. Then be sure to click the Save button. After doing this, have the user try logging in again.

If you are not using the WP Discourse plugin, we will need to give you more detailed instructions to fix the issue.

4 إعجابات

You’re right, I’m using WordPress and I made the change, I will ask user to try again, thank you so much!! :smiley:

إعجاب واحد (1)

It worked! Yeah! :smile: Thank you!

5 إعجابات