0Auth2 user linking within Discourse

Occasionally a user will experience an issue where each time they attempt to login they are asked to setup a new Discourse account. This commonly happens either on legacy accounts which are just now logging back into Discourse, or they signed up with username and password and are now trying to login as OAuth. In the past to resolve this, their Auth0 OAuth2 credentials need to be linked to their user ID in Discourse by running the below command from rails console within the discourse instance:

PluginStore.set('oauth2_basic', 'oauth2_basic_user_google-apps|tony.danza@aol.com', {"user_id":7235})

The problem seems to be this is no longer sticking, in fact it returns =>True where previously it would return Ok. I am at a pry prompt where in the past I didn’t think that was the case. When I exit Pry it also removes me from Rails Console.

Any idea what may be occurring here? Thanks!

Leveraging this plugin: GitHub - discourse/discourse-oauth2-basic: A basic OAuth2 plugin for use with Discourse · GitHub

That command is outdated, now the plugin uses the user associations table.

Can you share an example of the command that I will now run @Falco in replacement of it? Thank you for you help :bowing_man:

Following up for the latest command @Falco, thanks!

Any update or insight on the command @Falco?

This file shound give you an idea of how to construct the command you need:

Sorry for the delay, I had to upgrade discourse before I tried again. I gave the change a shot but didn’t experience success. Below is the example of what I have since tried that return true.

[1] pry(main)> PluginStore.set('oauth2_basic', 'user_associated_accounts_google-apps|tony.danza@gmail.com', {"user_id":1234})
=> true

Following up on this topic, thanks for the help!

휴가 중에 7번이나 멘션을 날려줘서 정말 고마워…

PluginStore.set 메서드를 사용하는 대신, 다음과 같은 방식으로 새로운 UserAssociatedAccount를 생성해야 합니다:

UserAssociatedAccount.create!(provider_name: 'oauth2_basic', provider_uid: 'google-apps|tony.danza@aol.com', user_id: 7235)

@Falco님, 죄송합니다. 커뮤니티 멤버들이 휴가를 가시면 상황을 공유하기가 어려워져서 저희도 어려움을 겪었습니다. 좋은 휴가 보내셨기를 바라며, 다시 한번 사과드립니다.

내일 말씀해 주신 제안을 시도해 보고 결과를 공유하겠습니다. 도움을 주셔서 다시 한번 감사합니다. :pray:

안녕하세요 @Falco, 이 건에 대해 후속 조취를 취하고 있습니다. 위에서 제안된 명령어를 실행하려고 하면 다음과 같은 오류가 발생합니다:

root@ip-172-31-20-121-app:/var/www/discourse# rails c
NOTE: Inheriting Faraday::Error::ClientError is deprecated; use Faraday::ClientError instead. It will be removed in or after version 1.0
Faraday::Error::ClientError.inherited called from /var/www/discourse/plugins/discourse-github/gems/2.6.5/gems/octokit-4.14.0/lib/octokit/middleware/follow_redirects.rb:14.
[1] pry(main)> UserAssociatedAccount.create!(provider_name: 'oauth2_basic', provider_uid: 'google-apps|nico@auth0.com', user_id: 1722)
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "associated_accounts_provider_uid"
DETAIL:  Key (provider_name, provider_uid)=(oauth2_basic, google-apps|nico@auth0.com) already exists.
from /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.1.3/lib/patches/db/pg.rb:69:in `async_exec_params'
Caused by PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "associated_accounts_provider_uid"
DETAIL:  Key (provider_name, provider_uid)=(oauth2_basic, google-apps|nico@auth0.com) already exists.

from /var/www/discours