FirebaseUI-iOS icon indicating copy to clipboard operation
FirebaseUI-iOS copied to clipboard

Github OAuth provider won't link with Google and Apple

Open drekka opened this issue 3 years ago • 2 comments

  • Swift
  • iOS version: 16
  • Firebase SDK version: 9.6.0
  • FirebaseUI version: master branch (Using SPM to add to SwiftUI project)
  • CocoaPods Version: N/A

Step 3: Describe the problem:

In my Firebase console authentication providers I have setup Google, Apple and Github as described in the Firebase UI doco. I also have also checked and enabled the automatic account linking option.

In my code (SwiftUI app) I have setup FirebaseAuthUI like this:

let authUI = FUIAuth.defaultAuthUI()!
authUI.delegate = self

authUI.providers = [
    FUIOAuth.appleAuthProvider(withAuthUI: authUI),
    FUIOAuth.githubAuthProvider(withAuthUI: authUI),
    FUIGoogleAuth(authUI: authUI),
]

So as to provide Apple, Google and Github sign on.

  • I can sign in using either Apple or Google and the Firebase console shows an account with my ID and both providers linked.

  • If I then try to sign on using Github I get the error

    Error Domain=FIRAuthErrorDomain Code=17012 "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address." UserInfo={FIRAuthErrorUserInfoNameKey=ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL, FIRAuthErrorUserInfoEmailKey=@gmail.com, FIRAuthErrorUserInfoUpdatedCredentialKey=<FIROAuthCredential: 0x6000009af520>, NSLocalizedDescription=An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.}

  • If I remove the account via from the Firebase console, then sign in using Github it works and creates an account with the GitHub provider.

  • If I then sign out and sign back in with a Google or Apple, it also logs in successfully. However when I check the Firebase console the GitHub provider has been removed from the account and replaced with the Google or Apple provider I signed in with.

It appears that the GitHib provider does not want to play nice with other providers.

Can you tell me if I'm doing anything wrong?

drekka avatar Jan 12 '23 13:01 drekka

I've now managed to solve one problem. Specifically the problem where the GitHub provider won't sign on if there is an Apple or Google provider already registered. I did it with this code:

extension Security: FUIAuthDelegate {

    func authUI(_: FUIAuth, didSignInWith user: User?, error: Error?) {
        if let error {
            let nsError = error as NSError
            if nsError.code == AuthErrorCode.accountExistsWithDifferentCredential.rawValue {
                pendingAuth = nsError.userInfo[AuthErrorUserInfoUpdatedCredentialKey] as? AuthCredential
            }

            signOnViewModel.error = error
            return
        }

        if let user {
            if let pendingAuth {
                Auth.auth().currentUser?.link(with: pendingAuth) { result, error in
                    self.pendingAuth = nil
                }
            }
        }
    }

Essentially this is a hack of the code I found on the Firebase site for dealing with AuthErrorCode.accountExistsWithDifferentCredentials. I found that if there is already a registration with the same email but a different provide, then when I attempt to sign in with the GitHub provider it throws this error.

In my code I then stash the GitHub credentials and ask the user to sign in with a different provider. Once they do that, it then uses the stashed GitHub credentials to link the GitHub provider.

it works in that I end up with one registration with both GitHub and Apple/Google providers attached.

However it's not a great user experience.

Nor does it solve the issues of registering Appel/Google after GitHub removing Github as a provider.

I've tried poking around in Auth.auth() and FUIAuth.defaultAuthUI() but I've not been able to find anything that will tell me what has already been registered for a specific email. I've called Auth.auth().fetchSignInMethods(forEmail:...) but it always returns an empty array.

Any advice????

drekka avatar Jan 13 '23 14:01 drekka

Hello,

Thank you for taking the time to submit this bug.

A new release is planned shortly for SwiftUI native Auth that replaces the previous Auth FirebaseUI, which should resolve this request.

In the meantime, we will close this issue, if this is not resolved in the new version - please feel free to create a new issue.

russellwheatley avatar Nov 17 '25 13:11 russellwheatley