Debug e risoluzione dei problemi comuni di DiscourseConnect

In qualità di amministratore di un forum che utilizza DiscourseConnect, potresti occasionalmente ricevere segnalazioni da utenti che, tentando di accedere al forum, vengono accolti da un messaggio di errore. Ad esempio: “C’è un problema con il tuo account. Contatta l’amministratore del sito.”

Abilitare il logging dettagliato di Discourse Connect

Per diagnosticare il problema, la prima cosa da fare è abilitare l’impostazione del sito “verbose discourse connect logging” su Discourse. Se questa impostazione era già abilitata, puoi accedere direttamente ai log del sito in Admin/Logs/Error Logs. Se l’impostazione non era precedentemente abilitata, dovrai chiedere all’utente di tentare nuovamente l’accesso, in modo da generare una voce di log relativa al tentativo di accesso fallito.

Leggere la voce di log

Vai su Admin/Logs/Error Logs e cerca una voce di log recente che inizi con Verbose SSO log: Record was invalid. Se hai difficoltà a trovare la voce, inserisci “Record was invalid” nella casella di ricerca in fondo alla pagina dei log. Clicca sulla voce di log, poi clicca sulla scheda “info” nella barra degli strumenti dei log:

Le informazioni di cui avrai bisogno sono la motivazione (indicata nella voce di log) e gli campi email e external_id (trovati nella sezione info).

Risolvere i problemi di accesso a DiscourseConnect legati a require_activation

Un problema comune con l’accesso SSO è: Record was invalid: User {:primary_email=> "has already been taken"}.

Ciò può verificarsi quando il parametro require_activation nel payload SSO è impostato su true e l’utente ha già un account su Discourse che o non ha ancora un single_sign_on_record associato, oppure ne ha uno, ma il external_id del record non corrisponde al external_id dell’utente che sta tentando di accedere.

Per confermare ciò, accedi alla console Rails del tuo forum e cerca un utente con l’indirizzo email utilizzato nel tentativo di accesso SSO fallito:

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

Ora, verifica se esiste un single_sign_on_record per questo utente:

sso_record = u.single_sign_on_record

Se l’utente esiste sul tuo forum ma non ha un record SSO, puoi crearne uno per lui utilizzando i valori del log SSO:

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

L’utente dovrebbe ora essere in grado di accedere.

Se esiste già un record SSO per l’utente, ma il suo external_id non corrisponde al external_id del tentativo di accesso fallito, dovrai investigare le cause di questa discrepanza. Un modo in cui ciò può accadere è se l’account di un utente è stato eliminato e poi ricreato sul sito del provider SSO. In tal caso, puoi aggiornare il record SSO per utilizzare il nuovo external_id:

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

L’utente dovrebbe ora essere in grado di accedere.

Se stai utilizzando il plugin WP Discourse e incontri il problema descritto sopra, consulta Validate Email Addresses with the WP Discourse plugin per dettagli su come risolvere il problema senza dover accedere alla console Rails.

17 Mi Piace

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 Mi Piace

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 Mi Piace

: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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

It worked! Yeah! :smile: Thank you!

5 Mi Piace