Skip to content

futureversecom/sdk-unity-futurepass

Repository files navigation

Unity FuturePass SDK

A FuturePass authentication plugin for Unity, by Futureverse

The Futurepass SDK is an Unity Engine plugin for authenticating users and managing access tokens with Futurepass—Futureverse’s identity and authentication system. It provides a seamless interface for custodial user login, token handling, and environment switching.

For more on FuturePass and the broader Futureverse developer ecosystem, visit the Futureverse Documentation Hub.

✨ Features

  • 🔐 Custodial Login via browser-based authentication
  • 🔄 Access & Refresh Token management
  • 🌍 Runtime Environment Switching (Production/Staging)
  • 🔗 Token callback events for login/logout/refresh handling

🧩 Installation - Package Manager via Git

  1. In the Unity Package Manger, click '+' -> "Add package from git URL".
  2. Paste the git url for this project and press "add"

🧩 Installation - Import .unitypackage

  1. In the Releases area of this repository, download the .unitypackage for your target version
  2. Right-click in the Project window in the Unity engine, and select "Import Package -> Custom Package"
  3. Navigate to your downloaded .unityproject file
  4. Press "Import" on the next window

📄 API Reference

FuturePassAuthentication

The primary source of functions and data when interacting with the FuturePass SDK

Properties
Environment CurrentEnvironment; // The current Futurepass environment (Development, Staging, or Production)
CustodialAuthenticationResponse LoadedAuthenticationDetails; // The current
Methods
SetEnvironment (Environment environment); // Set Futurepass environment (Development, Staging, or Production)
SetTokenAutoCache (bool cacheAutomatically); // Toggle whether refresh token is cached in PlayerPrefs
StartLogin(Action onSuccess, Action<Exception> onFailure); // Begin the custodial authentication process
AbortLogin(); // Cancel ongoing login, closing the web socket
RefreshToken(); // Request a new authentication packet using loaded refresh token
CacheRefreshToken(); // Encrypt and store loaded refresh token in PlayerPrefs
CacheRefreshToken(string refreshToken, string passKey); // Encrypt and store provided refresh token using passKey as encryption pass-key
LoginFromCachedRefreshToken(string passKey); // Load and decrypt cached refresh token, then request authentication

FuturePassExecutor

An optional scene object to demonstrate runtime functionality and API usage.
The inspector contains a text area to view loaded authentication data

Properties
FuturePassAuthentication.Environment environment; // Inspector enum field to set Futurepass environment
bool cacheRefreshToken; // Inspector toggle whether to automatically cache refresh token
Methods
StartLogin(); // Begin the custodial authentication process
AbortLogin(); // Cancel ongoing login, closing the web socket
RefreshToken(); // Request a new authentication packet using loaded refresh token
CacheRefreshToken(); // Encrypt and store loaded refresh token in PlayerPrefs
LoginFromCachedRefreshToken(string passKey); // Load and decrypt cached refresh token, then request authentication

CoroutineSceneObject

A utility object used to run coroutines from the static FuturePassAuthentication class

Properties
CoroutineSceneObject Instance; // Singleton reference to the scene object

CustodialHttpListener

Simple HTTP listener implmenetation to receive callbacks from custodial web requests

Properties
CustodialHttpListener Instance; // Singleton reference to the listener object
string ExpectedState; // The expected state value for validating CSRF protection
Methods
StartTokenAuthListener(Action<string,string,string> onAuthCodeReceived); // Create HttpListener and begin listening for callbacks. On receiving a valid packet, returns auth code details (authCode, state, ExpectedState)
StopAuthTokenListener(); // Close HttpListener connection
byte[] ConvertFromBase64String(string base64); // Convert a base64 string into a byte[]

🛠️ Getting Started: Using the Debug Functions

Add the FuturePass prefab to your game scene

This prefab has buttons for each major function in this API


Begin a play session, and press the "Start Login" button on your FuturePassExecutor component

This will open a web browser, beginning your custodial authentication process


Once login is complete, your browser will redirect to a http://localhost:3000/callback page with text that says "You may now close this webpage!". At this point, you may return to Unity and again inspect your authentication component.


Upon a successful login, the text area below the debug buttons will now contain the details of your authentication. If you fail authentication, or want to cancel mid-process, you may use the "Abort Login" button to close the webserver listening for the login callback.


Once a token has been provisioned, you may ask for a 'refresh' in order to request a new token without running through the custodial flow again. Press the "Refresh Token" button to trigger this process. After a second that the text area again updates with the new details of your authentication (you may need to mouse over the window to update its contents)


The "Cache Refresh Token" will encrpyt and cache the refresh token from your currently loaded authentication. You may cache up to one token per production environment.


The "Login From Cached Token" will load and decrypt this refresh token, and then perform the refresh flow to fetch a new authentication packet.


The refresh token is cached by default whenever you perform a custodial flow, or a refresh flow. You may disable this behaviour by un-ticking the "Cache Refresh Token" boolean.

🛠️ Getting Started: Process Login

using Auth = Futureverse.FuturePass.FuturePassAuthentication;

void Run() {
  Auth.SetEnvironment(Auth.Environment.Staging);
  Auth.StartLogin(onSuccess: () => {
    var token = Auth.LoadedAuthenticationDetails.AccessToken;
    var fpass = Auth.LoadedAuthenticationDetails.DecodedToken.Futurepass;
  }
}

🛠️ Getting Started: Login From Cached Token

Caching a token and using it to login allows for a smoother user experience. They do not need to repeat the custodial flow every time they launch the app, only if their token expires.

using Auth = Futureverse.FuturePass.FuturePassAuthentication;

// Call this function any time after a login has occured (either in this session or a previous one)
void CacheToken() {
  Auth.SetEnvironment(Auth.Environment.Staging);
  Auth.CacheRefreshToken();
}

// This function will attempt to locate a previously cached token, and login with it
void LoginFromToken() {
  Auth.LoginFromCachedRefreshToken(
    onSuccess: () => {
      var token = Auth.LoadedAuthenticationDetails.AccessToken;
    },
    onFailure: (ex) => {
      // Either no refresh token found, or the refresh token login process failured. 
      // Start a standard custodial login
    }
  );
}

📄 License

This SDK is released under the Apache License 2.0.

About

Unity SDK for the implementation of futurepass authentication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages