Stratkit Google Sign-In¶
Native Google Sign-In wrapper for Unity. Provides an async API to authenticate users via Google and retrieve an ID token for backend verification.
Supported Platforms¶
| Platform | SDK | Min Version |
|---|---|---|
| Android | Credential Manager (androidx.credentials) | API 21+ |
| iOS | Google Sign-In SDK 8.x | iOS 15.0+ |
| Editor | Mock provider (returns test token) | - |
Setup¶
1. Google Cloud Console¶
Create OAuth 2.0 client IDs in Google Cloud Console:
- Web application client ID — used as
WebClientId(required for both platforms) - iOS client ID — used as
IosClientId(required for iOS builds)
Android uses the Web Client ID directly with Credential Manager; no separate Android client ID is needed.
2. Configuration Asset¶
Create a GoogleSignInConfiguration ScriptableObject:
Right-click in Project > Create > Stratkit > Google Sign-In > GoogleSignInConfiguration
Fill in:
- WebClientId — your Web application OAuth client ID
- IosClientId — your iOS OAuth client ID (leave empty if iOS is not needed)
3. Initialize at Startup¶
Call Configure() once during bootstrap, before any sign-in attempt:
4. Sign In¶
try {
GoogleSignInResult result = await GoogleSignInService.SignInAsync();
string idToken = result.IdToken;
// Send idToken to your backend for verification
} catch (GoogleSignInException e) {
// Handle error (e.ErrorCode for specific failure reason)
}
Native SDK Dependencies¶
Native dependencies are managed via EDM4U (External Dependency Manager for Unity). The Editor/GoogleSignInDependencies.xml file declares:
Android:
- androidx.credentials:credentials:1.3.0
- androidx.credentials:credentials-play-services-auth:1.3.0
- com.google.android.libraries.identity.googleid:googleid:1.1.1
iOS:
- GoogleSignIn CocoaPod ~> 8.0
Run Assets > External Dependency Manager > Resolve after importing the package.
Build Post-Processing¶
The GoogleSignInBuildProcessor automatically handles:
- iOS: Adds the reversed client ID as a URL scheme in
Info.plist(required by the Google Sign-In SDK) - Android: Validates configuration at build time
API Reference¶
| Type | Description |
|---|---|
GoogleSignInService |
Static entry point — Configure() and SignInAsync() |
GoogleSignInResult |
Result containing IdToken, Email, DisplayName, UserId |
GoogleSignInConfiguration |
ScriptableObject with OAuth client IDs and scopes |
GoogleSignInException |
Exception with ErrorCode (Cancelled, NetworkError, ConfigurationError, etc.) |