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
Send the code challenge and the player's internal ID to your game server. From there, call ApproveCustomLogin (POST /sdk/custom_login/approve) to complete the link.
ApproveCustomLogin is a server-side endpoint. Call it from your game server, not from the game client directly.
Refer to your engine's documentation for handling deep links. The game client extracts the code challenge and forwards it to your game server. The server completes the link by calling ApproveCustomLogin.
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...
}
}How is this guide?