Depurar e corrigir problemas comuns do DiscourseConnect

Como administrador de um fórum que usa o DiscourseConnect, você pode ocasionalmente receber relatos de usuários de que, ao tentar fazer login no fórum, são recebidos por uma mensagem de erro. Por exemplo: “Há um problema com sua conta. Entre em contato com o administrador do site.”

Habilitando o registro detalhado (verbose) do Discourse Connect

Para depurar o problema, a primeira coisa que você precisa fazer é habilitar a Configuração do Site “verbose discourse connect logging” no Discourse. Se essa configuração já estava habilitada anteriormente, você pode ir diretamente aos logs do seu site em Admin/Logs/Error Logs. Se a configuração não estava habilitada anteriormente, você precisará pedir ao usuário que tente fazer login novamente para que você possa gerar uma entrada de log de sua tentativa de login falha.

Lendo a entrada do log

Vá para Admin/Logs/Error Logs e procure uma entrada de log recente que comece com Verbose SSO log: Record was invalid. Se tiver dificuldade para encontrar a entrada, digite ‘Record was invalid’ na caixa de pesquisa na parte inferior da página de logs. Clique na entrada do log. Em seguida, clique na aba ‘info’ na barra de ferramentas dos logs:

As informações de que você precisará são o motivo (fornecido na entrada do log) e o email e external_id (encontrados na seção de informações).

Resolvendo problemas de login do DiscourseConnect relacionados ao require_activation

Um problema comum com login SSO é: Record was invalid: User {:primary_email=>\"has already been taken\"}.

Isso pode acontecer quando o parâmetro require_activation no payload SSO está definido como true e o usuário já possui uma conta existente no Discourse que ainda não tem um single_sign_on_record associado a ela, ou possui um single_sign_on_record, mas o external_id do registro não corresponde ao external_id do usuário que está tentando fazer login.

Para confirmar isso, acesse o console Rails do seu fórum e pesquise por um usuário que tenha o endereço de e-mail usado na tentativa de login SSO falha:

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

Agora, verifique se há um single_sign_on_record para este usuário:

sso_record = u.single_sign_on_record

Se o usuário existir no seu fórum, mas não tiver um registro SSO, você pode criar um registro para ele usando os valores do log SSO:

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

O usuário agora deverá conseguir fazer login.

Se houver um registro SSO existente para o usuário, mas seu external_id não corresponder ao external_id da tentativa de login falha, você precisará investigar o motivo disso. Uma maneira como isso pode acontecer é se a conta de um usuário foi excluída e depois recriada no site do provedor SSO. Nesse caso, você pode atualizar o registro SSO para usar o novo external_id:

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

O usuário agora deverá conseguir fazer login.

Se você estiver usando o plugin WP Discourse e enfrentando o problema descrito acima, consulte Validate Email Addresses with the WP Discourse plugin para detalhes sobre como resolver o problema sem precisar acessar o console Rails.

17 curtidas

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 curtidas

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 curtidas

: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 curtidas

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 curtidas

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 curtida

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 curtidas

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 curtida

It worked! Yeah! :smile: Thank you!

5 curtidas