# Getting Started with Firebase Authentication in Unity

My first Firebase Authentication integration: app registration, SHA fingerprints, provider setup, and email account creation.

> I was looking for a third-party account SDK for an app aimed at international users. After comparing the options, I chose Firebase.

Integration was initially rough. I tried exporting an AAR from Android Studio into Unity, then exporting an Android Studio project from Unity. Neither attempt worked. I had not yet tried iOS.

The real problem was that I had not read the official documentation carefully. Google supplied a Unity package: importing it and doing a little configuration in the Firebase console was much simpler.

[Official Firebase Authentication Unity guide](https://firebase.google.com/docs/auth/unity/start)

## Register the app in Firebase

![Registering the app in the Firebase console](/media/cd4d0695/img1.png)

Make sure the registered package name matches the app's final package name.

## Add the SHA certificate fingerprint

Add the fingerprint in the app settings:

![Adding a SHA certificate fingerprint](/media/cd4d0695/img2.png)

## Download google-services.json

In the project described in this November 2022 note, I placed the file in `Asset/StreamingAssets` in the Unity project.

## Enable an authentication provider

![Enabling an authentication provider](/media/cd4d0695/img3.png)

## Import FirebaseAuth.unitypackage

Import the authentication package into Unity.

## Add test code

The following code tests account creation with an email address and password:

```
auth.CreateUserWithEmailAndPasswordAsync(email, password)
            .ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError(
                        "CreateUserWithEmailAndPasswordAsync encountered an error: "
                            + task.Exception
                    );
                    return;
                }

                // Firebase user has been created.
                FirebaseUser newUser = task.Result;
                Debug.LogFormat(
                    "Firebase user created successfully: {0} ({1})",
                    newUser.DisplayName,
                    newUser.UserId
                );
            });
```