You can let your users authenticate with Firebase using their Google Accounts by integrating Google Sign-In into your app.
- Ensure you have setup Firebase in your application
- Enable Google Sign-In in the Firebase console:
- In the Firebase console, open the Auth section.
- On the Sign in method tab, enable the Google sign-in method and click Save.
In order to sign in using Google accounts you will need to integrate Google Sign-In. You can do this using the Google Identity extension. The following guide uses this ANE however you can use any method you currently have to attain the id token.
Firstly, integrate Google Sign-In in your application by following the steps outlined in the Google Identity ANE.
You must ensure that you request the id token when setting up the extension, by setting
Then call sign in to authenticate your user using their Google account:
When sign in completes you'll have access to the id token and access token.
You use these to construct an
AuthCredential that you can pass to the
To create an
AuthCredential for Google use the
Then pass this to
signInWithCredential method will return the
For example on the
GoogleIdentityEvent.SIGN_IN event handler:
You can then use the
SIGNIN_WITH_CREDENTIAL_COMPLETE event to process the success sign-in
which will have the
FirebaseUser with a linked Google provider.
After a user signs in for the first time, a new user account is created and linked to the credentials—that is, the user name and password, phone number, or auth provider information—the user signed in with. This new account is stored as part of your Firebase project, and can be used to identify a user across every app in your project, regardless of how the user signs in.
In your apps, you can get the user's basic profile information from the
In your Firebase Realtime Database and Cloud Storage Security Rules, you can get the signed-in
user's unique user ID from the auth variable, and use it to control what data a user can access.
You can allow users to sign in to your app using multiple authentication providers by linking
auth provider credentials to an existing user account.
To sign out a user, call