Authenticate Using GitHub and Unity Stay organized with collections Save and categorize content based on your preferences.
You can let your users authenticate with Firebase using their GitHub accountsby integrating GitHub authentication into your app.
Before you begin
Before you can useFirebase Authentication,you need to:
Register your Unity project and configure it to use Firebase.
If your Unity project already uses Firebase, then it's alreadyregistered and configured for Firebase.
If you don't have a Unity project, you can download asample app.
Add theFirebaseUnity SDK (specifically,
FirebaseAuth.unitypackage) toyour Unity project.
Note that adding Firebase to your Unity project involves tasks both in theFirebase console and in your open Unity project(for example, you download Firebase config files from the console, then movethem into your Unity project).
Access theFirebase.Auth class
TheFirebaseAuth class is the gateway for all API calls.It is accessible throughFirebaseAuth.DefaultInstance.Firebase.Auth.FirebaseAuthauth=Firebase.Auth.FirebaseAuth.DefaultInstance;
Authenticate with Firebase
- Follow instructions forAndroid andiOS+to get a token for the signed-in GitHub user.
- After a user successfully signs in, exchange the access token for aFirebase credential, and authenticate with Firebase using the Firebasecredential:
Firebase.Auth.Credentialcredential=Firebase.Auth.GitHubAuthProvider.GetCredential(accessToken);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);});
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 the
Firebase.Auth.FirebaseUserobject:Firebase.Auth.FirebaseUseruser=auth.CurrentUser;if(user!=null){stringname=user.DisplayName;stringemail=user.Email;System.Uriphoto_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.stringuid=user.UserId;}
In yourFirebase Realtime Database andCloud StorageSecurity Rules, you can get the signed-in user's unique user ID from the
authvariable, and use it to control what data a user can access.
You can allow users to sign in to your app using multiple authenticationproviders bylinking auth provider credentials to anexisting user account.
To sign out a user, callSignOut():
auth.SignOut();
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 2025-12-17 UTC.