Account Linking
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 in Stash Studio.
- In the main menu, click Webshop.
- Go to Account Linking, then select the URL Schemes tab.
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 thechallenge
parameter. -
Call the Stash Linking Endpoint:
Use your engine’s HTTP or networking library to call the appropriate Stash API endpoint (such asLinkAccount
), 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
Import the Stash SDK
Follow these steps to add the Stash SDK to your Unity project:
- Download the latest Stash for Unity release.
- Import the
.unitypackage
file into your game with the Unity asset package import process. - (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_mxUDLml1PRbd0Io5I2g8oVg
The 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
idToken
from 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}");
}
The accounts are now linked and users are returned to the webshop to complete the flow that triggered the linking process.