A platform for community discussion. Free, open, simple.
FIX: update GitHub screen_name on login via GitHub
Arpit Jalan39be639c3744
diff --git a/lib/auth/github_authenticator.rb b/lib/auth/github_authenticator.rbindex 96fe5bfa7aa..c76fe9a59e2 100644--- a/lib/auth/github_authenticator.rb+++ b/lib/auth/github_authenticator.rb@@ -78,6 +78,12 @@ class Auth::GithubAuthenticator < Auth::Authenticatoruser = user_info.userresult.email = data[:email]result.email_valid = data[:email].present?++ # update GitHub screen_name+ if user_info.screen_name != screen_name+ user_info.screen_name = screen_name+ user_info.save!+ endelse# Potentially use *any* of the emails from GitHub to find a match or# register a new user, with preference given to the primary email.diff --git a/spec/components/auth/github_authenticator_spec.rb b/spec/components/auth/github_authenticator_spec.rbindex 37c14b15464..ae50424c904 100644--- a/spec/components/auth/github_authenticator_spec.rb+++ b/spec/components/auth/github_authenticator_spec.rb@@ -60,6 +60,17 @@ describe Auth::GithubAuthenticator doexpect(result.email_valid).to eq(true)end+ it 'can authenticate and update GitHub screen_name for existing user' do+ GithubUserInfo.create!(user_id: user.id, github_user_id: 100, screen_name: "boris")++ result = authenticator.after_authenticate(data)++ expect(result.user.id).to eq(user.id)+ expect(result.email).to eq(user.email)+ expect(result.email_valid).to eq(true)+ expect(GithubUserInfo.where(user_id: user.id).pluck(:screen_name)).to eq([user.username])+ end+it 'should use primary email for new user creation over other available emails' dohash = {extra: {