DEV: Migrate Github authentication to ManagedAuthenticator (#11170)

This commit adds an additional find_user_by_email hook to ManagedAuthenticator so that GitHub login can continue to support secondary email addresses

The github_user_infos table will be dropped in a follow-up commit.

This is the last core authenticator to be migrated to ManagedAuthenticator 🎉
This commit is contained in:
David Taylor
2020-11-10 10:09:15 +00:00
committed by GitHub
parent 586c8efbd8
commit cf21de0e7a
13 changed files with 86 additions and 209 deletions

View File

@@ -53,10 +53,9 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
end
# Matching an account by email
if primary_email_verified?(auth_token) &&
match_by_email &&
if match_by_email &&
association.user.nil? &&
(user = User.find_by_email(auth_token.dig(:info, :email)))
(user = find_user_by_email(auth_token))
UserAssociatedAccount.where(user: user, provider_name: auth_token[:provider]).destroy_all # Destroy existing associations for the new user
association.user = user
@@ -118,6 +117,13 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
retrieve_profile(user, association.info)
end
def find_user_by_email(auth_token)
email = auth_token.dig(:info, :email)
if email && primary_email_verified?(auth_token)
User.find_by_email(email)
end
end
def retrieve_avatar(user, url)
return unless user && url
return if user.user_avatar.try(:custom_upload_id).present?