Authenticate with Firebase using a custom authentication system and Unity (2024)

Stay organized with collections Save and categorize content based on your preferences.

You can integrate Firebase Authentication with a custom authentication system bymodifying your authentication server to produce custom signed tokens when a usersuccessfully signs in. Your app receives this token and uses it to authenticatewith Firebase.

Before you begin

  1. Before you can use Firebase Authentication, you need to:

    • Register your Unity project with your Firebase project.
    • Add the Firebase Unity SDK (specifically, FirebaseAuth.unitypackage) to your Unity project.

    Find detailed instructions for these initial setup steps in Add Firebase to your Unity project.

  2. Get your project's server keys:
    1. Go to the Service Accounts page in your project's settings.
    2. Click Generate New Private Key at the bottom of the Firebase Admin SDK section of the Service Accounts page.
    3. The new service account's public/private key pair is automatically saved on your computer. Copy this file to your authentication server.

Authenticate with Firebase

The FirebaseAuth class is the gateway for all API calls.It is accessible through FirebaseAuth.DefaultInstance.

Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

Call Firebase.Auth.FirebaseAuth.SignInWithCustomTokenAsync with the token fromyour authentication server.

  1. When users sign in to your app, send their sign-in credentials (forexample, their username and password) to your authentication server. Yourserver checks the credentials and returns acustom tokenif they are valid.
  2. After you receive the custom token from your authentication server, passit to Firebase.Auth.FirebaseAuth.SignInWithCustomTokenAsync to sign in theuser:
    auth.SignInWithCustomTokenAsync(custom_token).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithCustomTokenAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithCustomTokenAsync encountered an error: " + task.Exception); return; } Firebase.Auth.AuthResult result = task.Result; Debug.LogFormat("User signed in successfully: {0} ({1})", result.User.DisplayName, result.User.UserId);});

Next steps

After a user signs in for the first time, a new user account is created andlinked to the credentials—that is, the user name and password, phonenumber, or auth provider information—the user signed in with. This newaccount is stored as part of your Firebase project, and can be used to identifya 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 theFirebase.Auth.FirebaseUser object:

    Firebase.Auth.FirebaseUser user = auth.CurrentUser;if (user != null) { string name = user.DisplayName; string email = user.Email; System.Uri photo_url = user.PhotoUrl; // The user's Id, unique to the Firebase project. // Do NOT use this value to authenticate with your backend server, if you // have one; use User.TokenAsync() instead. string uid = user.UserId;}
  • 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 authenticationproviders by linking auth provider credentials to anexisting user account.

To sign out a user, call SignOut():

auth.SignOut();

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-13 UTC.

Authenticate with Firebase using a custom authentication system and Unity (2024)

FAQs

How to use Firebase authentication in Unity? ›

Before you can use Firebase Authentication, you need to:
  1. Register your Unity project and configure it to use Firebase. If your Unity project already uses Firebase, then it's already registered and configured for Firebase. ...
  2. Add the Firebase Unity SDK (specifically, FirebaseAuth. unitypackage ) to your Unity project.

How do I authorize with Firebase authentication? ›

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.

How do I add a custom domain to Firebase authentication? ›

Adding the domain to your email templates
  1. In the Firebase console, open the Templates page of the Authentication section.
  2. For each email template, do the following: Click the edit icon (edit). Click customize domain. Enter the domain you want to use.

How do I add authentication in unity? ›

In the Unity Editor menu, go to Edit > Project Settings…, then select Services > Authentication. Set ID Providers to Username/Password, then select Add. Select Save.

How do I use Firebase UI authentication? ›

In the Firebase console, open the Authentication section. On the Sign in method tab, enable the Email/Password provider. Note that email/password sign-in must be enabled to use email link sign-in. In the same section, enable Email link (passwordless sign-in) sign-in method and click Save.

How to connect Firebase database to Unity? ›

Add Firebase to your Unity project
  1. Prerequisites.
  2. Step 1: Create a Firebase project.
  3. Step 2: Register your app with Firebase.
  4. Step 3: Add Firebase configuration files.
  5. Step 4: Add Firebase Unity SDKs.
  6. Step 5: Confirm Google Play services version requirements.
  7. Set up a desktop workflow (beta)
  8. Supported Firebase products.

How do I add custom authentication? ›

The steps to add custom authentication are as follows:
  1. Enabling custom authentication.
  2. Building pages.
  3. Authenticate users.
  4. Save auth data.
  5. Access auth data.
  6. Update auth data.
  7. Logout.
Aug 14, 2024

How do I set up an authentication server in Firebase? ›

When users sign in to your app, send their sign-in credentials (for example, their username and password) to your authentication server. Your server checks the credentials and, if they are valid, creates a custom Firebase token and sends the token back to your app.

How do I deploy Firebase authentication? ›

Install the Firebase CLI tool npm install -g firebase-tools . Login into Firebase from the CLI firebase login . Run firebase init functions then select an existing project (that you created above). Select language as JavaScript for this example.

Is Unity Authentication free? ›

Increase engagement and provide consistent experiences by adding a player identity system to your game. It's built to integrate seamlessly with Unity projects and is free to use.

How to add Authentication in C#? ›

Steps For User Authentication:
  1. Step 1: START.
  2. Step 2: Take user details like name, username, and password.
  3. Step 3: Verify Password with constraint.
  4. Step 4: If Step 4 is successful then show the message Account Created else repeat Step 2 and Step 3 until Step 3 does not return Successful.
Oct 18, 2022

How do I set up an Authentication server? ›

Navigate to System > Security - Sign-on Settings. In the Authentication Server URL field, enter https:// followed by the host name configured during the Authentication Server installation.

How do I use Firebase remote config in Unity? ›

  1. Step 1: Add Remote Config to your app.
  2. Step 2: Set in-app default parameter values.
  3. Step 3: Get parameter values to use in your app.
  4. Step 4: Set parameter values.
  5. Step 5: Fetch and activate values.
  6. Step 6: Listen for updates in real time.
  7. Throttling.
  8. Next steps.

How to implement 2fa Firebase? ›

Enabling multi-factor authentication
  1. Open the Authentication > Sign-in method page of the Firebase console.
  2. In the Advanced section, enable SMS Multi-factor Authentication. ...
  3. If you haven't already authorized your app's domain, add it to the allow list on the Authentication > Settings page of the Firebase console.

How do I use Firebase authentication REST API? ›

How To Use Firebase Auth In Less Than 10 minutes
  1. Connect to Firebase Auth. To use Firebase Auth, you need to create a Firebase project and enable Firebase Auth with email and password. ...
  2. Signing up a user. ...
  3. Signing in a user. ...
  4. Sign out a user. ...
  5. Reset password. ...
  6. Call an authenticated API endpoint.

How to connect Firebase auth to database? ›

Connect your App to Firebase
  1. Create a Database.
  2. Add the Realtime Database SDK to your app.
  3. Configure Realtime Database Security Rules.
  4. Write to your database.
  5. Read from your database.
  6. Optional: Configure ProGuard.
  7. Prepare for Launch.
  8. Next Steps.

Top Articles
Corporate Bonds: An Introduction to Credit Risk
Simple food and how it might benefit you
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6169

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.