Account Linking
Learn how to connect a player's webshop session with their game client through account linking. Understand deep link setup, integration steps for different engines, and Unity-specific implementation using the Stash SDK.
Account linking connects a player's webshop session with their game client.
The webshop launches the game through a deep link (on mobile) or a QR code (on desktop). The deep link carries a session code. The game client attaches the player's authentication data to this code and sends both to the Stash API to complete login.
Deeplink setup
Configure a deep link scheme in Stash Studio. Use a scheme that clearly represents your game. For example, the demo app uses howlingwoods://.
Follow these steps:
Open your game instance
Open your game instance in Stash Studio.
Navigate to Webshop
In the main menu, click Webshop.
Configure URL Schemes
Go to Account Linking, then select the URL Schemes tab.
Interactive Demo
Integrate account linking
The example below uses Unity, but you can follow the same flow in other engines such as Unreal Engine, Godot, or custom web/native clients.
Obtain the Player's Authentication Token
Use the platform's authentication system (Google, Apple, or other providers) to retrieve a valid token or credential for the player.
Extract the Code Challenge
Parse the deep link or callback URL to extract the challenge parameter.
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 logic is the same across engines: collect the parameters securely and call the Stash linking API to complete the process.
Set up account linking in Unity
Use the Stash SDK to integrate account linking in Unity.
The SDK is optional. It provides convenient wrappers around the API endpoints, but you can also implement account linking with direct API calls.
Import the Stash SDK
Follow these steps to add the Stash SDK to your Unity project:
Import the package
Import the .unitypackage file into your game with the Unity asset package import process.
Import demo scenes (Optional)
Select the Scenes folder to import demo scenes.
Set up deep links
See the Unity deep linking overview for platform-specific instructions.
Let's take a look at the structure of the Stash's deep links.
stashggsample://link?challenge=QBHb5sIdj5RpEJTYZU2_mxUDLml1PRbd0Io5I2g8oVgThe key element in the link is the code challenge. Configure deep links correctly and add logic to extract the code challenge when your game launches through a deep link.
Extract the code challenge
With deep linking configured, you can extract the code challenge.
Use Unity's Application.deepLinkActivated event to handle deep link activations. This event triggers whenever the game launches or resumes from a Stash deep link.
In the onDeepLinkActivated handler, split the link to extract the code challenge.
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
Use Stash's LinkAccount method to link accounts. This method requires:
- The
idTokenfrom the previous step. - The internal user ID that's used for purchase identification.
- The code challenge associated with the linking request.
Refresh credentials before linking. Credentials older than 60 minutes expire and cause the linking process to fail.
//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}");
}How is this guide?