Sign in with Custom IDs
Sign in users to Vivox with custom identifiers.
Read time 2 minutesLast updated 2 days ago
If you already have an existing player management system that creates player IDs, you can use the Custom ID provider to link the identities.
Prerequisites:
- Set up a Unity Cloud project
- Make sure you have your project ID, environment ID, and environment name.
- Enable the UAS custom ID provider Make sure you have your Service Account credentials handy from this setup

- The game client sends the sign in request to the game back end
- The game back end either signs in the player using your custom logic or registers the player with a custom ID provider sent to UAS.
- UAS returns an access token to the game back end.
- The game back end then returns the access token to the game client.
- The game client then initializes the authentication service and the Vivox service to finish signing in the player.
- Register all users with the UAS custom ID provider on sign-in and retrieve and
accessTokenfor players.sessionTokens - Set up the AuthenticationService in the client using the and
accessTokensessionToken
Client-side setup
Together with the server side sign in set up, an access token has to be retrieved from your back end and processed with theAuthenticationServiceProcessAuthenticationTokensProcessAuthenticationTokensProcessAuthenticationTokensNote that the sample code is a method only, not a class. The access token needs to be retrieved from your backend. Refer to the Server-side setup below for more information on that.using Unity.Services.Authentication;using Unity.Services.Vivox;void SignUserWithCustomTokenWithAutoRefresh(){ try { // Check if a cached player already exists by checking if the session token exists if (AuthenticationService.Instance.SessionTokenExists) { // This call will sign in the cached player. await AuthenticationService.Instance.SignInAnonymouslyAsync(); Debug.Log("Cached user sign in succeeded!"); } else { var userTokens = // Fetch the user tokens using your method calls AuthenticationService.Instance.ProcessAuthenticationTokens(userTokens.AccessToken, userTokens.SessionToken) } // Shows how to get the playerID Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); await VivoxService.Instance.InitializeAsync(); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (Exception ex) { // Handle exceptions from your method call Debug.LogException(ex); }}
Server-side setup
During player sign-in, ensure that each player is registered with the UAS custom ID provider and retrieve aaccessTokensessionToken- Call the Token Exchange API to retrieve a stateless token.
- Call the Sign In With Custom ID API:
The response of this request will contain ancurl --location 'https://player-auth.services.api.unity.com/v1/projects/<PROJECT_ID>/authentication/server/custom-id' \--header 'Content-Type: application/json' \--header 'UnityEnvironment: <ENVIRONMENT_NAME>' \--header 'Authorization: Bearer <STATELESS_TOKEN' \--data '{ "externalId": "YOUR_CUSTOM_PLAYER_ID"}'
idTokensessionTokenAuthenticationServiceidTokenaccessToken