Depurar y solucionar problemas comunes de DiscourseConnect

Como administrador de un foro que utiliza DiscourseConnect, es posible que ocasionalmente reciba informes de usuarios que, al intentar iniciar sesión en el foro, reciben un mensaje de error. Por ejemplo: “Hay un problema con su cuenta. Póngase en contacto con el administrador del sitio”.

Habilitar el registro detallado de Discourse Connect

Para depurar el problema, lo primero que debe hacer es habilitar la configuración del sitio “verbose discourse connect logging” (registro detallado de Discourse Connect) en Discourse. Si esta configuración ya estaba habilitada, puede ir directamente a los registros de su sitio en Admin/Logs/Error Logs. Si la configuración no estaba habilitada previamente, deberá pedirle al usuario que intente iniciar sesión nuevamente para que pueda generar una entrada de registro de su intento de inicio de sesión fallido.

Leer la entrada del registro

Vaya a Admin/Logs/Error Logs y busque una entrada de registro reciente que comience con Verbose SSO log: Record was invalid. Si tiene dificultades para encontrar la entrada, ingrese “Record was invalid” en el cuadro de búsqueda en la parte inferior de la página de registros. Haga clic en la entrada del registro. Luego, haga clic en la pestaña “info” en la barra de herramientas de registros:

La información que necesitará es la razón (indicada en la entrada del registro) y el email y el external_id (encontrados en la sección de información).

Solucionar problemas de inicio de sesión en DiscourseConnect relacionados con require_activation

Un problema común con el inicio de sesión SSO es: Record was invalid: User {:primary_email=>\"has already been taken\"}.

Esto puede ocurrir cuando el parámetro require_activation en la carga útil de SSO está establecido en true y el usuario tiene una cuenta existente en Discourse que aún no tiene un single_sign_on_record asociado, o tiene un single_sign_on_record, pero el external_id del registro no coincide con el external_id del usuario que intenta iniciar sesión.

Para confirmar esto, ingrese a la consola de Rails de su foro y busque un usuario que tenga la dirección de correo electrónico utilizada en el intento fallido de inicio de sesión SSO:

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

Ahora, verifique si existe un single_sign_on_record para este usuario:

sso_record = u.single_sign_on_record

Si el usuario existe en su foro pero no tiene un registro SSO, puede crear uno para él utilizando los valores del registro SSO:

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

Ahora el usuario debería poder iniciar sesión.

Si existe un registro SSO para el usuario, pero su external_id no coincide con el external_id del intento de inicio de sesión fallido, deberá investigar por qué ocurrió esto. Una forma en que esto puede suceder es si la cuenta de un usuario ha sido eliminada y luego recreada en el sitio del proveedor de SSO. En este caso, puede actualizar el registro SSO para que utilice el nuevo external_id:

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

Ahora el usuario debería poder iniciar sesión.

Si está utilizando el complemento WP Discourse y tiene el problema descrito anteriormente, consulte Validate Email Addresses with the WP Discourse plugin para obtener detalles sobre cómo resolver el problema sin necesidad de acceder a la consola de Rails.

17 Me gusta

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 Me gusta

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 Me gusta

: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 Me gusta

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 Me gusta

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 me gusta

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 Me gusta

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 me gusta

It worked! Yeah! :smile: Thank you!

5 Me gusta