Setup
1. Create a Passport Client
You will need to create and configure a passport client for each application type (e.g. a mobile app, a website) where you intend to use Passport. If you haven't already setup a project in Immutable Hub, login and add a new project from the dashboard.
When you add a project you will need to name it and choose whether your project will run on Immutable zkEVM or Immutable X. You then need to choose whether your project will run on Testnet or Mainnet and name the environment.
Once your project and environment are setup, navigate to its Passport Configuration page and add a new client. You will need choose the Application Type (Native or Web), then add your Application Name, a Redirect URL and a Logout URL to save the client.
Configuring your Passport client
2. Configure Passport
- Web
- Unity
- Unreal
Install Immutable's JS/TS SDK
Next, we'll need to initialise the Passport client inside your application as follows:
export const passportInstance = new passport.Passport({
baseConfig: {
environment: config.Environment.SANDBOX, // or config.Environment.PRODUCTION
publishableKey:
process.env.NEXT_PUBLIC_PUBLISHABLE_KEY || '<YOUR_PUBLISHABLE_KEY>', // replace with your publishable API key from Hub
},
clientId: process.env.NEXT_PUBLIC_CLIENT_ID || '<YOUR_CLIENT_ID>', // replace with your client ID from Hub
redirectUri: 'http://localhost:3000/redirect', // replace with one of your redirect URIs from Hub
logoutRedirectUri: 'http://localhost:3000/logout', // replace with one of your logout URIs from Hub
audience: 'platform_api',
scope: 'openid offline_access email transact',
});
Examples on how to integrate Passport with common web frameworks and 3rd party libraries are available here.
More detail on each of the fields:
Field | Description |
---|---|
publishableKey | Publishable Keys are used to identify your integration for tracking and analytics purposes. You can find it by logging into Immutable Hub, choosing your Project and Environment then navigating to the API Keys page. |
clientId | Client IDs are used to identify your the passport client you wish to use in this integration. You can find it by logging into Immutable Hub, choosing your Project and Environment then navigating to Passport Configuration page. |
redirectUri | The URI of your application that users will be redirected to after successfully authenticating. This value must match one of the Redirect URLs that have been set in your Immutable Hub's Passport Configuration for the Passport client you are wanting to integrate. If no value is specified, then Passport will default to the redirect logout mode. |
logoutRedirectUri | The URI of your application that users will be redirected to after successfully logging out. This value must match one of the Logout URLs that have been set in your Immutable Hub's Passport Configuration for the Passport client you are wanting to integrate. If no value is specified, then Passport will default to your Passport client's first logout redirect URI. |
audience | The platform_api audience is required for all Passport clients. |
scope | The transact , openid & offline_access scopes are all currently required for all Passport clients. Request the email scope to access the user's email. Learn about scopes here. |
popupOverlayOptions | Options for disabling the Passport overlays that appear when the Passport transaction confirmation pop-up is requested. The overlays are designed to help the user focus the pop-up or open the pop-up when Passport detects the pop-up was blocked. There are two Passport pop-up overlays, a generic overlay that is always shown when the pop-up opens and an overlay that appears when the pop-up has been blocked. Each overlay has a separate option to disable depending on whether you want to show both overlays, only the blocked overlay or disable the blocked overlay to implement a custom solution for handling blocked pop-ups. |
Troubleshooting
Error Code | Cause | Resolution |
---|---|---|
INVALID_CONFIGURATION | The environment configuration or OIDC Configuration is incorrect | Verify that you are passing an environment configuration and OIDC configuration, and that all the mandatory properties have been set |
Install Immutable's Unity SDK
Create a script with the following code and bind it to an object:
- Device Code Authorisation
- PKCE (Recommended for Android, iOS, macOS and WebGL)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Immutable.Passport;
public class InitPassport : MonoBehaviour
{
private Passport passport;
async void Start()
{
// Replace with your actual Passport Client ID
string clientId = "YOUR_IMMUTABLE_CLIENT_ID";
// Set the environment to SANDBOX for testing or PRODUCTION for production
string environment = Immutable.Passport.Model.Environment.SANDBOX;
// Initialise Passport
passport = await Passport.Init(clientId, environment, logoutRedirectUri: "https://www.example.com");
}
}
Once initialised, you can access the Passport instance from anywhere in your project via Passport.Instance
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Immutable.Passport;
public class InitPassport : MonoBehaviour
{
private Passport passport;
async void Start()
{
// Replace with your actual Passport Client ID
string clientId = "YOUR_IMMUTABLE_CLIENT_ID";
// Set the environment to SANDBOX for testing or PRODUCTION for production
string environment = Immutable.Passport.Model.Environment.SANDBOX;
// Your game's redirect URLs
string redirectUri = "mygame://callback";
string logoutRedirectUri = "mygame://logout";
// Initialise Passport
passport = await Passport.Init(clientId, environment, redirectUri, logoutRedirectUri);
}
}
Once initialised, you can access the Passport instance from anywhere in your project via Passport.Instance
.
To get PKCE working on Android and iOS, you need to set up a few more things.
- Android
- iOS
On Android, we utilise Chrome Custom Tabs (if available) to seamlessly connect gamers to Passport from within the game.
For example, on Unity 2019.4, you must upgrade from 3.4.* to 3.4.3 (see Android's blog post):
- In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Base Gradle Template under the Build section
- Open the newly generated
Assets/Plugins/Android/baseProjectTemplate.grade
file - Update
classpath 'com.android.tools.build:gradle:3.4.0'
toclasspath 'com.android.tools.build:gradle:3.4.3'
- In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Main Manifest and Custom Main Gradle Template under the Build section
- Open the newly generated
Assets/Plugins/Android/AndroidManifest.xml
file. Add the following code inside the<application>
element:
<activity
android:name="com.immutable.unity.RedirectActivity"
android:exported="true" >
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mygame" android:host="callback" />
<data android:scheme="mygame" android:host="logout" />
</intent-filter>
</activity>
- Open the newly generated
Assets/Plugins/Android/mainTemplate.gradle
file. Add the following code insidedependencies
block:
compileSdkVersion
must be at least 33. This is usually the same value as the targetSdkVersion
, which you can set in Build Settings -> Player Settings -> Android -> Other Settings -> Target API Level.implementation('androidx.browser:browser:1.5.0')
The application will now open when the device processes any link that starts with mygame://callback
or mygame://logout
.
See the sample app AndroidManifest.xml and mainTemplate.gradle for examples.
Proguard
If you enable Minify in your project settings, you will need to add a custom Proguard file to your project.
- In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Proguard File under the Build section
- Open the newly generated
Assets/Plugins/Android/proguard-user.txt
file. Add the following code inside the<application>
element
-dontwarn com.immutable.**
-keep class com.immutable.** { *; }
-keep interface com.immutable.** { *; }
-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.** { *; }
See the sample app proguard-user.txt for an example.
- In Unity go to Build Settings -> Player Settings -> iOS -> Other Settings -> Supported URL schemes
- Increment the Size number
- Add your URL scheme in the Element field, e.g. if the deeplink URL is
mygame://callback
, add the schememygame
to the field.
Install Immutable's Unreal SDK
3. Use Passport
Passport is now setup in your application, you are now ready to explore:
- Passport identity where you will walk you through the different authentication methods Passport supports
- Passport wallet where you will learn how to interact with the Passport wallet