Third-party authentication
Openfort's embedded signers are fully compatible with any authentication provider that supports JWT-based, stateless authentication. This guide shows how to integrate third-party authentication providers in your Unity game.
Follow the guide on how to configure third party auth to learn more.
Supported Providers
The Unity SDK supports the following third-party authentication providers:
- firebase - Google's mobile and web application development platform
- supabase - Open source Firebase alternative
- playFab - Microsoft's backend platform for live games
- accelByte - Backend-as-a-service platform for game developers
- lootLocker - Game backend platform
- custom - Your own authentication provider with JWT support
- oidc - Any OpenID Connect compliant provider
Methods
Initialize with Third-Party Provider
Initialize the OpenfortSDK with your third-party authentication provider.
Method Signature:public static UniTask<OpenfortSDK> Init(
string publishableKey,
string shieldPublishableKey = null,
bool shieldDebug = false,
string thirdPartyProvider = null,
Func<string, Task<string>> getThirdPartyToken = null
)
string publishableKey
- Your Openfort publishable keystring shieldPublishableKey
- Optional Shield publishable key for enhanced securitystring thirdPartyProvider
- The authentication provider name (e.g., "firebase", "playfab", "custom")Func<string, Task<string>> getThirdPartyToken
- Callback function that returns the current authentication token
UniTask<OpenfortSDK>
- Initialized SDK instance
Firebase Authentication Example
Here's a complete example using Firebase authentication with Google Play Games:
using System;
using System.Threading.Tasks;
using UnityEngine;
using Firebase;
using Firebase.Auth;
using Firebase.Extensions;
using Openfort.OpenfortSDK;
using Openfort.OpenfortSDK.Model;
using Cysharp.Threading.Tasks;
#if UNITY_ANDROID
using GooglePlayGames;
using GooglePlayGames.BasicApi;
#endif
public class ThirdPartyAuthManager : MonoBehaviour
{
private OpenfortSDK openfort;
private FirebaseAuth firebaseAuth;
private const string PublishableKey = "YOUR_OPENFORT_PUBLISHABLE_KEY";
private const string ShieldKey = "YOUR_SHIELD_KEY"; // Optional
private async void Start()
{
// Initialize Firebase first
await InitializeFirebase();
// Then initialize Openfort with Firebase provider
await InitializeOpenfort();
}
private async Task InitializeFirebase()
{
var dependencyStatus = await FirebaseApp.CheckAndFixDependenciesAsync();
if (dependencyStatus == DependencyStatus.Available)
{
firebaseAuth = FirebaseAuth.DefaultInstance;
Debug.Log("Firebase initialized successfully");
// Listen to auth state changes
firebaseAuth.StateChanged += OnAuthStateChanged;
}
else
{
Debug.LogError(quot;Could not resolve Firebase dependencies: {dependencyStatus}");
}
}
private async Task InitializeOpenfort()
{
try
{
openfort = await OpenfortSDK.Init(
publishableKey: PublishableKey,
shieldPublishableKey: ShieldKey,
thirdPartyProvider: "firebase",
getThirdPartyToken: GetFirebaseToken
);
Debug.Log("Openfort SDK initialized with Firebase provider");
}
catch (Exception e)
{
Debug.LogError(quot;Failed to initialize Openfort: {e.Message}");
}
}
// Callback function to provide Firebase token to Openfort
private async Task<string> GetFirebaseToken(string requestId)
{
if (firebaseAuth.CurrentUser != null)
{
try
{
// Get fresh ID token from Firebase
var token = await firebaseAuth.CurrentUser.TokenAsync(false);
return token;
}
catch (Exception e)
{
Debug.LogError(quot;Failed to get Firebase token: {e.Message}");
throw;
}
}
throw new Exception("No authenticated Firebase user");
}
// Sign in with email/password
public async UniTask SignInWithEmail(string email, string password)
{
try
{
var authResult = await firebaseAuth.SignInWithEmailAndPasswordAsync(email, password);
Debug.Log(quot;Email sign-in successful: {authResult.User.Email}");
// Configure wallet after successful sign-in
await ConfigureWallet();
}
catch (Exception e)
{
Debug.LogError(quot;Email sign-in failed: {e.Message}");
throw;
}
}
private void OnAuthStateChanged(object sender, EventArgs eventArgs)
{
var user = firebaseAuth.CurrentUser;
if (user != null)
{
Debug.Log(quot;User authenticated: {user.UserId}");
// User is signed in
}
else
{
Debug.Log("User signed out");
// User is signed out
}
}
public async UniTask SignOut()
{
firebaseAuth.SignOut();
await openfort.Logout();
Debug.Log("User signed out from Firebase and Openfort");
}
private void OnDestroy()
{
if (firebaseAuth != null)
{
firebaseAuth.StateChanged -= OnAuthStateChanged;
}
}
[Serializable]
private class EncryptionSessionResponse
{
public string session;
}
}
Authentication Response
Upon successful authentication, you'll receive a response containing:
{
"id": "pla_cc9ed2b7-c5f5-4c43-8dca-c4b104ba1762",
"object": "player",
"createdAt": 1710976453,
"linkedAccounts": [
{
"provider": "firebase",
"disabled": false,
"externalUserId": "firebase_user_123"
}
]
}
Example Repository
Firebase Auth with Unity
Complete integration example with Google Play Games using Firebase Auth as a third-party auth provider.