Integrate Firebase with Openfort in Unity

Learn how to integrate Firebase backend and Openfort with your game


Firebase is Google's all-encompassing app development platform, providing game developers with an array of backend tools powered by Google Cloud.

Within Unity, we've integrated the Firebase SDK to facilitate backend functionalities. Coupled with the Google Play Games plugin for Unity, it ensures a secure and efficient login for Android users.

The integration is further enhanced with the Openfort Firebase extension, which incorporates the Openfort SDK. This enables Unity clients to directly leverage Openfort's blockchain capabilities, allowing for sophisticated blockchain interactions within the gaming environment.

Application Workflow#

Integration workflow


  • Sign in to dashboard.openfort.xyz and create a new project.

  • You need a Google Play Developer account.

  • You need a Google Cloud project.

  • Clone or download the repository and open it with Unity 2021.3. When opening the project, select Ignore on this popup:

    ignore popup

    Once opened, you will see some reference errors. We will solve this in the next step by importing the Firebase SDK.

  • Follow the Firebase-Unity setup guide. On step 4, you just need to import FirebaseAuth and FirebaseFirestore packages:

    import Firebase packages

    Do it one by one and disable ExternalDependencyManager folder before importing:

    import unity package

    Most reference errors should be solved by now. If UnityEditor.iOS.Extensions.Xcode error is still standing, select Firebase.Editor asset, disable Validate References and choose Apply:

    resolve packages
  • Create a keystore Follow this guide to create a new keystore for the Unity project.

  • Find SHA1 certificate fingerprint You need to extract the certificate fingerprint from the created keystore. Follow this video tutorial on how to do it, it also covers the creation of the keystore.

    This is the command that you will need to run:

    keytool -list -v -keystore "path/to/your/keystore" -alias "your_key_alias"

Set up Firebase#

Add Google sign-in provider#

Go to the Firebase console, select your project and select Authentication:

setup authentication firebase

After selecting Get started, select Google as a sign-in provider:

choose the auth method

Activate Enable toggle, choose a public-facing name and select Save:

setup google

A popup will appear. Copy the Web client ID and the Web client secret somewhere safe and choose Done. You will see your Google provider enabled:

enabled google

Select the provider and choose Project Settings. Under Your apps section select Add fingerprint and add your SHA1 certificate fingerprint. Then choose Save:

add fingerprint
certificate for SHA1

Add Google Play sign-in provider#

Select Add new provider and choose Google Play:

Choose Google Play

Activate Enable toggle, enter the credentials you just saved and choose Save:

Play games setup

Both Google and Google Play sign-in providers are ready:

auth providers

Install Openfort Extension#

Go to the Firebase Extensions Hub and choose Install in Firebase console:

extension hub

Choose your project to continue:

Alt text

Set up your billing profile and follow the instructions until you need to insert the Openfort API Secret key and choose Create secret. Also set Cloud Firestore to Sync:

configure extension

Finally choose Install extension. After 3-5 minutes you will see the extension installed:

Alt text

Now select Get started and under How this extension works section find Configure Openfort webhooks. Copy the URL:

setup webhook

Set up Openfort#

Add webhook#

Choose Add webhook:

Alt text

Paste the webhook URL you got from the Firebase extension and leave the Type as it is. Choose Add webhook:

Alt text

Add a Contract#

Choose Add contract:

Alt text

This sample requires a contract to run. We use 0xbed6a05ce8719bc00db1cc81a814192c82be1bb1 (NFT contract deployed in 80002 Amoy). You can use the same for this tutorial:

Alt text

Add a Policy#

Choose Add policy:

Alt text

We aim to cover gas fees for users. Set a new gas policy:

Alt text

Now, add a rule so our contract uses this policy:

Alt text

Set up Google Play#

Reminder: Use the same Google account you used for setting up your Firebase app.

Create a new app#

Go to Play Console and create a new app. Enter app details (it's important you select Game), confirm policies and select Create app:

Alt text

Under Grow --> Play Games Services --> Setup and management --> Configuration, select Create new Play Games Services project and choose your Firebase project as the cloud project. Then select Use:

Alt text

Add credentials#

Add Android OAuth client credential

Under Credentials section choose Add credential:

Alt text

Select Android:

add android credential

Scroll down and select Create OAuth client:

create OAuth client

Choose Create OAuth Client ID:

create OAuth client popup

This will open the Google Cloud console. Now select Android as Application type, enter a Name and fill the Package name with the Unity app package name (found in the Android Platform Player Settings):

setup client id gcp

Alt text

Enter your SHA1 certificate fingerprint and choose CREATE:

verify SHA1 create

Now you can download the JSON and choose OK:

download JSON

Go back to the Google Play console, select Done and choose your newly created Android OAuth client. Then select Save changes:

Alt text

Add Game server/Web OAuth client credential

Go back to Configuration and select Add credential:

Alt text

Choose Game server, refresh OAuth clients, select Web client (auto created by Google Service) (it was created automatically during this process) and select Save changes:

Alt text

Finally copy the OAuth client ID:

copy the oauth client

Set up Unity project#

Reminder: Make sure Android is selected as a platform in Build settings.

Go to Window --> Google Play Games --> Setup --> Android setup:

Alt text

Paste the Game server OAuth client ID you just copied under Client ID:

setup google play games

Go to the Google Play console and on your app's configuration select Get resources:

Alt text

Copy the Android (XML):

Alt text

In Unity, paste it in Resources Definition and then select Setup:

setup google play games

Finally, go to the Firebase console and under your app configuration, download the google-services.json:

Alt text

Import it in your Unity project Assets folder to make sure every credential is up to date.

Test on Android#

Upon building and running the game on an Android device, the registration/login process is automated via Google Play Games, resulting in a streamlined user experience.


Upon completing the above steps, your Unity game will be fully integrated with Openfort and Firebase. Always remember to test every feature before deploying to guarantee a flawless player experience.

Get support#

If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.

If you have questions, comments, or need help with code, we're here to help: