Debug and fixing common DiscourseConnect issues

As the administrator of a forum that is using DiscourseConnect, you may occasionally get reports from users that when they attempt to login to the forum, they are greeted by an error message. For example: “There is a problem with your account. Please contact the site’s administrator.”

Enabling verbose discourse connect logging

To debug the issue, the first thing you need to do is to enable the ‘verbose discourse connect logging’ Site Setting on Discourse. If this setting was previously enabled, you can go directly to your site logs at Admin/Logs/Error Logs. If the setting was not previously enabled, you will need to ask the user to attempt logging in again so that you can generate a log entry of their failing login attempt.

Reading the log entry

Go to Admin/Logs/Error Logs and look for a recent log entry that starts with Verbose SSO log: Record was invalid. If you have trouble finding the entry, enter ‘Record was invalid’ into the search box at the bottom of the logs page. Click on the log entry. Then click on the ‘info’ tab on the logs toolbar:

The information that you will need is the reason (given in the log entry), and the email and external_id (found in the info section.)

Solving require_activation DiscourseConnect login issues

A common issue with SSO login is: Record was invalid: User {:primary_email=>"has already been taken"}.

This can happen when the require_activation parameter in the SSO payload is set to true and the user has an existing account on Discourse that either does not yet have a single_sign_on_record associated with it, or has a single_sign_on_record, but the record’s external_id doesn’t match the external_id of the user who is trying to login.

To confirm this, enter your forum’s Rails console, and search for a user who has the email address that was used in the failed SSO login attempt:

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

Now, check if there is a single_sign_on_record for this user:

sso_record = u.single_sign_on_record

If the user exists on your forum, but does not have an SSO record, you can create a record for them using the values from the SSO log:

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

The user should now be able to login.

If there is an existing SSO record for the user, but its external_id doesn’t match the external_id from the failed login attempt, you will need to look into why this has happened. One way this can happen is if a user’s account has been deleted and then recreated on the SSO provider site. In this case, you can update the SSO record to use the new external_id:

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

The user should now be able to login.

If you are using the WP Discourse plugin and running into the issue outlined above, see Validate Email Addresses with the WP Discourse plugin for details about how to resolve the issue without having to access the Rails console.

Last edited by @JammyDodger 2024-05-26T07:21:30Z

Check documentPerform check on document:
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도 활성화되어 있었습니다. 다른 해결책이 있을까요? 정말 막막합니다 :frowning:

특정 사용자의 SSO 로그인에 문제가 있는 건가요, 아니면 사이트에서 SSO가 아예 작동하지 않는 건가요?

특정 사용자만

verbose sso logging 사이트 설정을 활성화했는지 확인해 주세요. 그렇게 하셨다면, 사용자가 로그인하려고 할 때 사이트 로그에서 해당 오류를 찾을 수 있나요? 오류 로그를 여기에 공유해 주시면 도움을 드릴 수 있습니다. 로그에 공개하고 싶지 않은 데이터가 있다면, 개인 메시지로 보내 주세요.

2개의 좋아요

이 내용이 도움이 되시나요? 필요하신 내용인가요?

해당 상황에 연루된 멤버(또는 이 문제를 보고한 유일한 멤버)의 로그 세부 정보입니다.

정말 감사합니다!

1개의 좋아요

감사합니다. 도움이 됩니다. SSO 제공자 사이트가 WordPress 사이트인 것 같습니다. SSO를 위해 WP Discourse 플러그인을 사용하고 계신가요? 그렇다면 플러그인의 최신 버전을 사용하고 있다면, 해당 사용자의 프로필 페이지로 이동하여 ‘이메일 주소 확인됨’ 확인란을 선택해 보세요. 그런 다음 저장 버튼을 클릭하는 것을 잊지 마세요. 이 작업을 완료한 후, 사용자에게 다시 로그인하도록 요청해 주세요.

WP Discourse 플러그인을 사용하지 않는 경우, 문제를 해결하기 위해 더 자세한 지침을 제공해 드릴 필요가 있습니다.

4개의 좋아요

맞아요, 저는 워드프레스를 사용 중이고 변경 사항을 적용했습니다. 사용자에게 다시 시도해 달라고 요청할게요. 정말 감사합니다!! :smiley:

1개의 좋아요

동작했어요! 네! :smile: 감사합니다!

5개의 좋아요