Unity Quickstart
Installation
Install the Openfort SDK
There are two ways to install the SDK:
Since .dll files are stored on Git Large File Storage, you must download and install git-lfs from here.
- Open the Package Manager
- Click the add + button and select "Add package from git URL..."
Enter
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTaskand click 'Add' - Click the add + button and select "Add package from git URL..."
Enter
https://github.com/openfort-xyz/openfort-csharp-unity.git?path=/src/Packages/OpenfortSDKand click 'Add'
Since .dll files are stored on Git Large File Storage, you must download and install git-lfs from here.
- Open your project's Packages/manifest.json file
- Add
com.cysharp.unitask:https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTaskin the dependencies block - Add
com.openfort.sdk:https://github.com/openfort-xyz/openfort-csharp-unity.git?path=/src/Packages/OpenfortSDKin the dependencies block
Set your auth providers
- Navigate to the auth providers page on the Openfort dashboard
- Click Auth providers Methods in the side bar in the users page
- Configure the methods you want users to be able to login with
Get your API keys
In the API keys section, you'll find:
- Publishable Key: Safe to expose in client-side environment
- Secret Key: Must be kept secure and used only server-side
To generate non-custodial wallets:
- Scroll to the Shield section and click Create Shield keys
- Store the encryption share safely when it appears (you'll only see it once)
- You'll receive:
- Shield Publishable Key: Safe for client-side use
- Shield Secret Key: Keep secure, server-side only
Set up
Before you begin, make sure you have set up your publishable key app from the Openfort Dashboard.
Initialize Openfort in your Unity project
Init
Initialize the Openfort SDK with your configuration.
Method Signature:public static async UniTask<OpenfortSDK> Init(
string publishableKey,
string shieldPublishableKey = null,
Func<string, Task<string>> getThirdPartyToken = null
)string publishableKey- Your Openfort publishable key (required)string shieldPublishableKey- Shield publishable key for embedded wallets (optional)Func<string, Task<string>> getThirdPartyToken- Token provider function (optional)
UniTask<OpenfortSDK>- Initialized SDK instance
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
using Openfort.OpenfortSDK;
using Openfort.OpenfortSDK.Model;
public class OpenfortManager : MonoBehaviour
{
private OpenfortSDK openfort;
// Replace with your actual keys from the Openfort dashboard
private const string PUBLISHABLE_KEY = "YOUR_OPENFORT_PUBLISHABLE_KEY";
private const string SHIELD_PUBLISHABLE_KEY = "YOUR_SHIELD_PUBLISHABLE_KEY"; // Optional, for embedded wallets
private async void Start()
{
await InitializeOpenfort();
}
private async UniTask InitializeOpenfort()
{
try
{
// Initialize the SDK
openfort = await OpenfortSDK.Init(
publishableKey: PUBLISHABLE_KEY,
shieldPublishableKey: SHIELD_PUBLISHABLE_KEY, // Can be null if not using embedded wallets
shieldDebug: false // Set to true for debugging in development
);
Debug.Log("Openfort SDK initialized successfully");
// You can now use the SDK
// Example: Check if user is already logged in
await CheckUserSession();
}
catch (OpenfortException e)
{
Debug.LogError(quot;Openfort initialization failed: {e.Message}, Type: {e.ErrorType}");
}
catch (Exception e)
{
Debug.LogError(quot;Unexpected error during initialization: {e.Message}");
}
}
private async UniTask CheckUserSession()
{
try
{
// Try to get current user (will fail if not logged in)
var user = await openfort.GetUser();
Debug.Log(quot;User already logged in: {user.Id}");
}
catch
{
Debug.Log("No active user session");
}
}
}You're ready to build!
With Openfort configured in your Unity project, you can now:
For a complete example of Openfort integration in Unity, check out our sample project.