Account Linking

Let’s walk through how to implement account linking using your game client.

The process is straightforward: first, set up deep link handling in your game client. On your webshop, you can provide a button or display a QR code that launches your game via a deep link, passing a unique session code to the game. The game client then receives this session code, attaches the player’s authentication data, and sends both to the Stash API to complete the login process.

Begin by configuring your preferred deep linking scheme in Stash Studio. For instance, in our demo app, we used the scheme howlingwoods://. Choose a scheme that clearly represents your game.

  1. Open your game instance in Stash Studio.
  2. In the main menu, click on Webshop.
  3. Go to Account Linking, then select the URL Schemes tab.

Integration

While our example below will focus on Unity, you can integrate Stash account linking into other engines or technologies (such as Unreal Engine, Godot, or custom web/native clients) by following the same general flow:

  1. Obtain the Player’s Authentication Token:
    Use the platform’s authentication system (e.g., Google, Apple, or other providers) to retrieve a valid token or credential for the player.

  2. Extract the Code Challenge:
    Parse the deep link or callback URL to extract the challenge parameter, which is required for linking.

  3. Call the Stash Linking Endpoint:
    Use your engine’s HTTP or networking library to call the appropriate Stash API endpoint (such as LinkAccount), passing the code challenge, internal player ID, and authentication token.

Refer to your engine’s documentation for handling deep links and making HTTP requests. The core logic remains the same: securely collect the required parameters and invoke the Stash linking API to complete the process.

Unity guide

In this guide, we’ll demonstrate how to integrate account linking using the Stash SDK. However, using the SDK is optional—the SDK simply provides convenient wrappers around our API endpoints. You can also implement account linking yourself by making direct calls to the relevant API endpoints if you prefer.

Import the Stash SDK

  1. Download the latest Stash for Unity release.
  2. Import the .unitypackage file into your game using the local asset package import process.
  3. Optionally select the Scenes folder to import demo scenes.

Unity’s documentation has a deep linking overview, as well as platform-specific instructions.

Let’s take a look at the structure of the Stash’s deep links.

Stash deep link
stashggsample://link?challenge=QBHb5sIdj5RpEJTYZU2_mxUDLml1PRbd0Io5I2g8oVg

The key element in the deep link is the code challenge. You’ll need to ensure deep links are correctly configured, and also implement logic to extract the code challenge from the link when your game is launched via a deep link.

Extract the code challenge

With deep linking configured, you can extract the code challenge. There’s an example below but you should use Unity’s Application.deepLinkActivated event and their deep linking documentation to complete the process.

The onDeepLinkActivated event handler is invoked every time the game is launched or resumed using Stash’s deep link. The link is then split and the code challenge is extracted.

onDeepLinkActivated
public void onDeepLinkActivated(string url) {
  // Extract the challenge parameter from the link.
  var challenge = url.Split("/link?challenge=")[1];
  if (!string.IsNullOrEmpty(challenge)) {
    // Work with code challenge...
  }
}

Linking Accounts

You use Stash’s LinkAccount method to link accounts. This method uses the idToken from the last step, as well as:

  • The internal user ID that’s used for purchase identification.
  • The code challenge associated with the linking request.
ℹ️

Stash recommends refreshing credentials before linking to Stash. Credentials older than 60 minutes are considered expired, which causes the linking process to fail.

Link accounts
//Wrap in try-catch block and handle StashRequestError appropriately.
try
{
  LinkResponse response = await StashClient.LinkAccount(_stashChallenge, InternalPlayerId, idToken);
	//Linking successful, prompt player to return back to the webshop.
}
catch (StashRequestError e)
{
  Debug.LogError($"[STASH][Apple] Account linking failed. Code: {e.Code}, Message: {e.Message}");
}

The accounts are now linked and users are returned to the webshop to complete the flow that triggered the linking process.

Was this page helpful?