Management API Reference

Authentication

Social Login (OAuth)

Create a script with the following code and bind it to an object.

The SDK exports a method called AuthenticateWithOAuth that implements the pooling OAuth flow. The method takes an OAuthInitRequest object as a parameter. The object contains the provider, the redirect URL, and the pooling option.


_30
using System.Collections;
_30
using System.Collections.Generic;
_30
using UnityEngine;
_30
using Openfort.OpenfortSDK;
_30
using Openfort.OpenfortSDK.Model;
_30
_30
public class InitOpenfort : MonoBehaviour
_30
{
_30
private OpenfortSDK openfort;
_30
_30
async void Start()
_30
{
_30
string publishableKey = "YOUR_OPENFORT_PUBLISHABLE_KEY";
_30
openfort = await OpenfortSDK.Init(publishableKey);
_30
}
_30
_30
public async void OnGoogleClicked()
_30
{
_30
OAuthInitRequest request = new OAuthInitRequest()
_30
{
_30
Provider = OAuthProvider.FACEBOOK,
_30
UsePooling = false,
_30
Options = new OAuthInitRequestOptions()
_30
{
_30
RedirectTo = "mygame://callback"
_30
},
_30
};
_30
await openfort.AuthenticateWithOAuth(request);
_30
}
_30
}

Openfort is now accessible from anywhere via Openfort.Instance.

Standalone Windows applications do not support window deep linking from a web browser to the application. Modify the request above to:


_10
OAuthInitRequest request = new OAuthInitRequest()
_10
{
_10
Provider = OAuthProvider.FACEBOOK,
_10
};

Android, iOS and macOS#

Android setup#

On Android, we utilize Chrome Custom Tabs (if available) to seamlessly connect gamers to Passport from within the game.

UNITY VERSIONS BELOW 2021.3

To check if Chrome Custom Tabs are available, older Unity versions may require a specific Gradle plugin version. For example, on Unity 2019.4, you must upgrade from 3.4.* to 3.4.3 (see Android's blog post):

  1. In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Base Gradle Template under the Build section
  2. Open the newly generated Assets/Plugins/Android/baseProjectTemplate.grade file
  3. Update classpath com.android.tools.build:gradle:3.4.0 to classpath com.android.tools.build:gradle:3.4.3
  1. In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Main Manifest and Custom Main Gradle Template under the Build section
  2. Open the newly generated Assets/Plugins/Android/AndroidManifest.xml file. Add the following code inside the <application> element:

_10
<activity
_10
android:name="com.openfort.unity.RedirectActivity"
_10
android:exported="true" >
_10
<intent-filter android:autoVerify="true">
_10
<action android:name="android.intent.action.VIEW" />
_10
<category android:name="android.intent.category.DEFAULT" />
_10
<category android:name="android.intent.category.BROWSABLE" />
_10
<data android:scheme="mygame" android:host="callback" />
_10
</intent-filter>
_10
</activity>

  1. Open the newly generated Assets/Plugins/Android/mainTemplate.gradle file. Add the following code inside dependencies block:

For this version of the Chrome Custom Tabs to work, the 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.

Proguard

If you enable Minify in your project settings, you will need to add a custom Proguard file to your project.

  1. In Unity go to Build Settings -> Player Settings -> Android -> Publishing Settings -> Enable Custom Proguard File under the Build section
  2. Open the newly generated Assets/Plugins/Android/proguard-user.txt file. Add the following code inside the <application> element

_10
-dontwarn com.openfort.**
_10
-keep class com.openfort.** { *; }
_10
-keep interface com.openfort.** { *; }
_10
_10
-dontwarn androidx.**
_10
-keep class androidx.** { *; }
_10
-keep interface androidx.** { *; }

The application will now open when the device processes any link that starts with mygame://callback.

iOS setup#

  1. In Unity go to Build Settings -> Player Settings -> iOS -> Other Settings -> Supported URL schemes.
  2. Increment the Size number.
  3. Add your URL scheme in the Element field, e.g. if the deeplink URL is mygame://callback, add the scheme mygame to the field.

Uppon successful authentication, the SDK will return a token that can be used to authenticate the user in your application.

response.json

_16
{
_16
"player": {
_16
"id": "pla_cc9ed2b7-c5f5-4c43-8dca-c4b104ba1762",
_16
"object": "player",
_16
"createdAt": 1710976453,
_16
"linkedAccounts": [
_16
{
_16
"provider": "facebook",
_16
"disabled": false,
_16
"externalUserId": "2"
_16
}
_16
]
_16
},
_16
"token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImNmODNlMTM1N2VlZmI4YmRmMTU0Mjg1MGQ2NmQ4MDA3ZDYyMGU0MD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