Link Multiple Auth Providers to an Account in Unity Stay organized with collections Save and categorize content based on your preferences.
linkWithCredentials() from working correctly in some projects. See the issue report for a workaround and the status of a fix.You can allow users to sign in to your app using multiple authenticationproviders by linking auth provider credentials to an existing user account.Users are identifiable by the same Firebase user ID regardless of theauthentication provider they used to sign in. For example, a user who signed inwith a password can link a Google account and sign in with either method in thefuture. Or, an anonymous user can link a Facebook account and then, later, signin with Facebook to continue using your app.
Before you begin
Add support for two or more authentication providers (possibly includinganonymous authentication) to your app.
TheFirebaseAuth class is the gateway for all API calls.It is accessible throughFirebaseAuth.DefaultInstance.Firebase.Auth.FirebaseAuthauth=Firebase.Auth.FirebaseAuth.DefaultInstance;
Link auth provider credentials to a user account
To link auth provider credentials to an existing user account:
- Sign in the user using any authentication provider or method.
- Complete the sign-in flow for the new authentication provider up to, but not including, calling one of the
Firebase.Auth.FirebaseAuth.SignInAndRetrieveDataWithCredentialAsyncmethods. For example, get the user's Google ID token, Facebook access token, or email and password. Get a
Google Sign-InFirebase.Auth.Credentialfor the new authentication provider: Facebook LoginFirebase.Auth.Credentialcredential=Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken,googleAccessToken);
Email-password sign-inFirebase.Auth.Credentialcredential=Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
Firebase.Auth.Credentialcredential=Firebase.Auth.EmailAuthProvider.GetCredential(email,password);
Pass the
Firebase.Auth.Credentialobject to the signed-in user'sLinkWithCredentialAsyncmethod:auth.CurrentUser.LinkWithCredentialAsync(credential).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("LinkWithCredentialAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("LinkWithCredentialAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("Credentials successfully linked to Firebase user: {0} ({1})",result.User.DisplayName,result.User.UserId);});
The call to
LinkWithCredentialAsyncwill fail if the credentials are already linked to another user account. In this situation, you must handle merging the accounts and associated data as appropriate for your app:// Gather data for the currently signed in User.stringcurrentUserId=auth.CurrentUser.UserId;stringcurrentEmail=auth.CurrentUser.Email;stringcurrentDisplayName=auth.CurrentUser.DisplayName;System.UricurrentPhotoUrl=auth.CurrentUser.PhotoUrl;// Sign in with the new credentials.auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("SignInAndRetrieveDataWithCredentialAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("SignInAndRetrieveDataWithCredentialAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("User signed in successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);// TODO: Merge app specific details using the newUser and values from the// previous user, saved above.});
If the call toLinkWithCredentialAsync succeeds, the user can now sign in usingany linked authentication provider and access the same Firebase data.
Unlink an auth provider from a user account
A single Firebase user account can have multiple authentication providers linked to it (for example, email/password, Google, Facebook), which lets the user sign in to the same Firebase account through different methods.
If you unlink an authentication provider from a user's account, they can no longer sign in with that provider.
Important: If a user signs in again with the same provider after it hasbeen unlinked, Firebase creates a new, separate user account instead ofrestoring link to the original account.To unlink an auth provider from a user account, pass the provider ID to theUnlinkAsync method. You can get the provider IDs of the authproviders linked to a user by callingProviderData.
// Unlink the sign-in provider from the currently active user.// providerIdString is a string identifying a provider,// retrieved via FirebaseAuth.FetchProvidersForEmail().auth.CurrentUser.UnlinkAsync(providerIdString).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("UnlinkAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("UnlinkAsync encountered an error: "+task.Exception);return;}// The user has been unlinked from the provider.Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("Credentials successfully unlinked from user: {0} ({1})",result.User.DisplayName,result.User.UserId);});
Troubleshooting
If you encounter errors when trying to link multiple accounts, see thedocumentation on verified email addresses.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.