Interface implementation-based token generation
Learn about interface implementation-based token generation.
Read time 1 minuteLast updated 20 hours ago
If you want to control how Vivox Access Tokens (VATs) are generated, create a class that implements the Vivox SDK’s
IVivoxTokenProviderVivoxService.Instance.SetTokenProviderIVivoxTokenProvider.GetTokenAsyncIVivoxTokenProvider.GetTokenAsyncIVivoxTokenProvider.GetTokenAsyncTo subscribe
Before initializing the Vivox SDK, you must register yourIVivoxTokenProviderVivoxService.Instance.SetTokenProvider(new CustomTokenProvider());
Fetch the token
Create the payload with all of the parameters provided in the overridden method, even if some are empty, and send it to your secure server to generate your Vivox Access Token. Best practice is to send all the parameters; only what’s needed for the payload will be returned. Use the payload as input into theGetTokenAsyncTo learn more about generating server-side tokens, refer to Generate a token on a secure server.public class VoiceManager : MonoBehaviour{ async void Start() { // Must be done before any other Vivox action otherwise tokens will not be generated properly. VivoxService.Instance.SetTokenProvider(new VivoxTokenProvider()); await UnityServices.InitializeAsync(); await VivoxService.Instance.InitializeAsync(); }}class VivoxTokenProvider : IVivoxTokenProvider{ public Task<string> GetTokenAsync(string issuer = null, TimeSpan? expiration = null, string targetUserUri = null, string action = null, string channelUri = null, string fromUserUri = null, string realm = null) { // Implement token fetching logic here. // The method parameters contain the necessary information for crafting the request payload. // This will be called whenever a token is needed for a Vivox action }}