Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github OAuth provider won't link with Google and Apple #1130

Open
drekka opened this issue Jan 12, 2023 · 1 comment
Open

Github OAuth provider won't link with Google and Apple #1130

drekka opened this issue Jan 12, 2023 · 1 comment

Comments

@drekka
Copy link

drekka commented Jan 12, 2023

  • 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, [email protected], 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
Copy link
Author

drekka commented Jan 13, 2023

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????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant