A lightweight plugin that bridges the mobile Google Sign-In SDKs to Unity for Android and iOS. This package gives you a simple C# interface to Android's Credential Manager and the iOS GoogleSignIn SDK.
The usage of this plug-in is stricly for returning a googleId Token for authentication. It does not currently support requesting scopes.
Eligibility for the Google Open Source Software Vulnerability Rewards Program is determined by the Google Open Source Software Vulnerability Reward Program Rules.
- Modern & Secure: Uses the latest mobile SDKs, not outdated WebViews.
- Backend Agnostic: Get a Google ID Token to authenticate with any service you want (Firebase, Okta, your own backend, etc.).
- Simple C# Events: Just subscribe to
OnSignInSuccessandOnSignInErrorto get the result. - Unity 6 Ready: Built and tested for Unity 6.5+.
Before integrating this plugin, you must configure your application identity definitions directly in the Google Cloud Platform (GCP) Console.
- Go to the Google Cloud Console.
- Select your project (or create a new one).
- Go to APIs & Services > Credentials.
- Configure the OAuth Consent Screen: Define your application's public name, support email, and standard authorization scopes (e.g.,
openid,email,profile). - Create a Web Client ID (Mandatory):
- Click Create Credentials > OAuth Client ID.
- Select Web application as the application type.
- Label this credential (e.g.,
Server Web Client ID). - Copy the resulting Web Client ID (looks like
123456-abc.apps.googleusercontent.com). This represents the "Audience" (aud) claim of your ID Tokens and is required for both platforms.
- In the GCP Console, click Create Credentials > OAuth Client ID again.
- Select Android as the application type.
- Enter your Unity application's unique Package Name (e.g.,
com.yourcompany.mygame). - Paste your SHA-1 fingerprint. Retrieve this by executing
keytoolagainst your development or release keystore:bash keytool -keystore path-to-keystore.keystore -list -v - Note: GCP associates this native Android Client ID with your Web Client ID automatically.
- In the GCP Console, click Create Credentials > OAuth Client ID.
- Select iOS as the application type.
- Enter your matching iOS Bundle ID (e.g.,
com.yourcompany.mygame). - Copy the Reversed Client ID (looks like
com.googleusercontent.apps.12345...) listed on the credential details page. This value is required to set up the iOS redirect URL scheme.
Choose the path that matches your current development state. Packages for Unity can be found in Releases. These instructions assume that you have downloaded siwg_unity_mobile_plugin.unitypackage locally.
- Create Project: Open Unity Hub and create a new project using the URP (Universal Render Pipeline) template. Must use Unity 6 LTS.
- Switch Platforms: Go to File > Build Profiles. Select Android and click Switch Platform. Do the same for iOS.
- Import Dependencies: Ensure the External Dependency Manager for Unity (EDM4U) is installed in your project to manage native libraries.
- Import This Plugin: Go to Assets > Import Package > Custom Package and select
siwg_unity_mobile_plugin.unitypackagefrom the location that you downloaded it. Ensure all files are checked and click Import. - Proceed to Section 3 (Final Configuration).
- Backup: Always back up your project before importing new native plugins.
- Prerequisite Check: Ensure you have EDM4U installed. If you have an older Google Sign-In plugin, remove it entirely.
- Import This Plugin: Go to Assets > Import Package > Custom Package and select the
siwg_unity_mobile_plugin.unitypackagefrom the location that you downloaded it. Ensure all files are checked and click Import. - Template Warning: This plugin includes
baseProjectTemplate.gradleandsettingsTemplate.gradle.- If you do not already have these templates, they will be added automatically.
- If you already have custom templates, Unity will not overwrite them. You must manually merge the Kotlin 1.9.24 definitions into your existing templates (see Section 3).
- Proceed to Section 3 (Final Configuration).
- Go to Window > Google Sign-In Native > Settings.
- Paste your Web Client ID into the first field.
- Paste your iOS Reversed Client ID into the second field.
- Click Save Settings.
- Go to Assets > External Dependency Manager > Android Resolver > Force Resolve.
- Wait for the success message. This downloads the native
googleidandandroidxlibraries.
- Create Manager: Create an empty GameObject in your initial scene named
GoogleSignInManager. - Attach Script: Attach the
GoogleSignInManager.csscript to it. - Assign Settings: Drag the
GoogleSignInNativeSettingsasset (fromAssets/GoogleSignInNative/Resources) into the Sign In Settings slot on the script. - Subscribe to Events & Trigger Sign-In: Create a controller script to subscribe to
GoogleSignInManager.OnSignInCompletedandGoogleSignInManager.OnSignInFailed, then callStartSignIn()when the user clicks your sign-in button:
using UnityEngine;
public class MyAuthController : MonoBehaviour
{
private void OnEnable()
{
GoogleSignInManager.OnSignInCompleted += HandleSignInSuccess;
GoogleSignInManager.OnSignInFailed += HandleSignInFailure;
}
private void OnDisable()
{
GoogleSignInManager.OnSignInCompleted -= HandleSignInSuccess;
GoogleSignInManager.OnSignInFailed -= HandleSignInFailure;
}
public void OnSignInButtonClick()
{
GoogleSignInManager.Instance.StartSignIn();
}
private void HandleSignInSuccess(string idToken)
{
Debug.Log($"[Auth] Success! ID Token received: {idToken.Substring(0, 15)}...");
// Send this ID token to your backend server or custom authentication provider
}
private void HandleSignInFailure(string error)
{
Debug.LogError($"[Auth] Google Sign-in failed: {error}");
}
}
- Ensure your Package Name in Player Settings matches your GCP OAuth Credentials exactly.
- Ensure your Minimum API Level is 34 or higher.
- Click Build and Run.
- Unity will generate an Xcode project. Open the
.xcworkspacefile. - In the Signing & Capabilities tab, select your Development Team.
- The plugin automatically adds the URL Scheme for you. Run on a physical device.
-
In GoogleSignInNativeAndroid.androidilb > gradleTemplate.properties you may need to append
android.builtInKotlin=trueif your project hasandroid.builtInKotlin=false. You can check this by runninggrep -i kotlin gradle.propertiesunder YOUR_UNITY_PROJECT/Library/Bee/Android/Prj/IL2CPP/Gradle. Kotlin was not enabled by default on versions of Unity older that 6.5. This is due to Unity 6.5 updating to Android Gradle Plugin (AGP) 9.x.x. -
In GoogleSignInNativeAndroid.androidlib > build.gradle the following block of code is used to ensure that we do not have Kotlin version conflicts when building the .androidlib:
kotlin {
compilerOptions {
freeCompilerArgs.add("-Xskip-metadata-version-check")
}
}
This is because the com.google.android.libraries.identity.googleid Library used was built with Kotlin 2.4.x while the default for Unity is 2.1.0. This block can be removed once Unity updates to a default Kotlin version of 2.4.x or greater.
This project is not intended for active development. Issues and contributions are handled on a best effort basis. This open source solution is intended to enhance the Google customer experience. For product support, please see support.google.com. Eligibility for the Google Open Source Software Vulnerability Rewards Program is determined by the Google Open Source Software Vulnerability Reward Program Rules.