The Firebase Auth Unity Sample demonstrates user authentication and user profile operations using Firebase Authentication with the Firebase Unity SDK.
- Unity 5.3 or higher.
- Xcode 10.1 or higher (when developing for iOS).
- Android SDK (when developing for Android).
- Register your iOS app with Firebase.
- Create a project in the
Firebase console,
and associate your iOS application.
- You should use
com.google.FirebaseUnityAuthTestApp.devas the package name while you're testing.- If you do not use the prescribed package name you will need to update
the bundle identifier as described in the
Optional: Update the Project Bundle Identifierbelow.
- If you do not use the prescribed package name you will need to update
the bundle identifier as described in the
- You should use
- Enable Authentication in the project.
- Go to the Firebase console,
- Select the Auth tab in the sidebar.
- Select the Sign-In Method tab
- Enable Email/Password and Anonymous sign-in providers.
- Download the
GoogleService-Info.plistfile associated with your Firebase project from the console. This file identifies your iOS app to the Firebase backend, and will need to be included in the sample later. - For further details please refer to the general instructions which describes how to configure a Firebase application for iOS.
- Create a project in the
Firebase console,
and associate your iOS application.
- Download the Firebase Unity SDK and unzip it somewhere convenient.
- Open the sample project in the Unity editor.
- Select the
File > Open Projectmenu item. - Click
Open. - Navigate to the sample directory
testappin the file dialog and clickOpen.
- Select the
- Open the scene
MainScene.- Navigate to
Assets/Firebase/Sample/Authin theProjectwindow. - Double click on
MainScenefile to open.
- Navigate to
- Import the
Firebase Authplugin.- Select the Assets > Import Package > Custom Package menu item.
- From the Firebase Unity SDK
downloaded previously, import
FirebaseAuth.unitypackagefrom the directory that matches the version of Unity you use:- Unity 5.x and earlier use the .NET 3.x framework, so you need to
import the
dotnet3/FirebaseAuth.unitypackagepackage . - Unity 2017.x and newer allow the use of the .NET 4.x framework. If
your project is configured to use .NET 4.x, import the
dotnet4/FirebaseAuth.unitypackagepackage.
- Unity 5.x and earlier use the .NET 3.x framework, so you need to
import the
- When the Import Unity Package window appears, click the Import button.
- Add the
GoogleService-Info.plistfile to the project.- Navigate to the
Assets/Firebase/Sample/Authfolder in theProjectwindow. - Drag the
GoogleService-Info.plistdownloaded from the Firebase console into the folder.- NOTE:
GoogleService-Info.plistcan be placed anywhere under theAssetsfolder.
- NOTE:
- Navigate to the
- Optional: Update the Project Bundle Identifier
- If you did not use
com.google.FirebaseUnityAuthTestApp.devas the project package name you will need to update the sample's Bundle Identifier.- Select the
File > Build Settingsmenu option. - Select
iOSin thePlatformlist. - Click
Player Settings - In the
Player Settingspanel scroll down toBundle Identifierand update the value to the package name you provided when you registered your app with Firebase.
- Select the
- If you did not use
- Build for iOS
- Select the
File > Build Settingsmenu option. - Select
iOSin thePlatformlist. - Click
Switch Platformto selectiOSas the target platform. - Wait for the spinner (compiling) icon to stop in the bottom right corner of the Unity status bar.
- Click
Build and Run, when Xcode opens stop the build. - Configure the Xcode project for push messaging.
- Select the
Unity-iPhoneproject from theNavigator area. - Select the
Capabilitiestab from theEditor area. - Switch
Push NotificationstoOn.
- Select the
- Build the Xcode project by selecting
Project->Runfrom the menu.
- Select the
- See the Using the Sample section below.
- Register your Android app with Firebase.
- Create a project in the
Firebase console,
and attach your Android app to it.
-
You should use
com.google.FirebaseUnityAuthTestApp.devas the package name while you're testing.- If you do not use the prescribed package name you will need to update
the bundle identifier as described in the
Optional: Update the Project Bundle Identifierbelow.
- If you do not use the prescribed package name you will need to update
the bundle identifier as described in the
-
To generate a SHA1, first you will need to set the keystore in the Unity project.
- Locate the
Publishing SettingsunderPlayer Settings. - Select an existing keystore, or create a new keystore using the toggle.
- Select an existing key, or create a new key using "Create a new key".
- Locate the
-
After setting the keystore and key, you can generate a SHA1 by running this command:
keytool -exportcert -list -v -alias <key_name> -keystore <path_to_keystore>
-
- Enable Authentication in the project.
- Go to the Firebase console,
- Select the Auth tab in the sidebar.
- Select the Sign-In Method tab
- Enable Email/Password and Anonymous sign-in providers.
- Download the
google-services.jsonfile associated with your Firebase project from the console. This file identifies your Android app to the Firebase backend, and will need to be included in the sample later.- For further details please refer to the general instructions which describes how to configure a Firebase application for Android.
- Create a project in the
Firebase console,
and attach your Android app to it.
- Download the Firebase Unity SDK and unzip it somewhere convenient.
- Open the sample project in the Unity editor.
- Select the
File > Open Projectmenu item. - Click
Open. - Navigate to the sample directory
testappin the file dialog and clickOpen.
- Select the
- Open the scene
MainScene.- Navigate to
Assets/Firebase/Sample/Authin theProjectwindow. - Double click on
MainScenefile to open.
- Navigate to
- Import the
Firebase Authplugin.- Select the Assets > Import Package > Custom Package menu item.
- From the Firebase Unity SDK
downloaded previously, import
FirebaseAuth.unitypackagefrom the directory that matches the version of Unity you use:- Unity 5.x and earlier use the .NET 3.x framework, so you need to
import the
dotnet3/FirebaseAuth.unitypackagepackage . - Unity 2017.x and newer allow the use of the .NET 4.x framework. If
your project is configured to use .NET 4.x, import the
dotnet4/FirebaseAuth.unitypackagepackage.
- Unity 5.x and earlier use the .NET 3.x framework, so you need to
import the
- When the Import Unity Package window appears, click the Import button.
- Add the
google-services.jsonfile to the project.- Navigate to the
Assets/Firebase/Sample/Authfolder in theProjectwindow. - Drag the
google-services.jsondownloaded from the Firebase console into the folder.- NOTE:
google-services.jsoncan be placed anywhere under theAssetsfolder.
- NOTE:
- Navigate to the
- Optional: Update the Project Bundle Identifier
- If you did not use
com.google.FirebaseUnityAuthTestApp.devas the project package name you will need to update the sample's Bundle Identifier.- Select the
File > Build Settingsmenu option. - Select
Androidin thePlatformlist. - Click
Player Settings - In the
Player Settingspanel scroll down toBundle Identifierand update the value to the package name you provided when you registered your app with Firebase.
- Select the
- If you did not use
- Build for Android
- Select the
File > Build Settingsmenu option. - Select
Androidin thePlatformlist. - Click
Switch Platformto selectAndroidas the target platform. - Wait for the spinner (compiling) icon to stop in the bottom right corner of the Unity status bar.
- Click
Build and Run.
- Select the
- See the Using the Sample section below.
You must enable Email/Password and Anonymous authentication sign-in method in your Firebase project in the Firebase console and also sign your application with the key registered with the Firebase project otherwise sign-in operations will fail.
The app provides email and password text input fields which control the user associated with the action performed by each of the following buttons:
- The
Create Userbutton attempts to register a user with the specified email and password. If the user is already present an error will be reported. - The
Sign In With Passwordbutton attempts to sign in the user with the specified email and password. If the user is already signed in the sign-in process will fail. - The
Sign In With Credentialsbutton creates an Auth credential from the specified email and password. - The
Delete Userbutton attempts to delete the user associated with the specified email address.
The user database can be viewed in the Firebase console. by:
- Selecting the
Authsidebar. - Selecting the
Userstab.
https://firebase.google.com/support/
Copyright 2016 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.