Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How to properly implement server generated VAT for vivox actions?

Discussion in 'Vivox (Voice & Text Chat)' started by miraz_tiger, May 11, 2023.

  1. miraz_tiger

    miraz_tiger

    Joined:
    Mar 21, 2023
    Posts:
    3
    Hello,

    I am currently using vivox sdk version 15.1.200000-pre.1 with Unity 2021.3.21f1. My project is linked with unity dashboard and I am not using test mode (mtu1xp backend is being used. Also not using unity authentication package).

    UnityVivoxLink.JPG

    I want to use server generated token. So I generated my VAT token in my server & used it in my client project. It worked & I thought I successfully logged in using my server generated login token. Then instead of my server generated token I used -
    • Case 1: Empty string.
    • Case 2: Random string like - "Hello World" or "I am Token"
    In case of "Case 1", I got an error while trying to login as expected.

    But in case of "Case 2", I successfully logged in to vivox even joined a channel the same way which was not suppose to. If "Case 2" is working then the whole process of token generation doesn't make any sense. I even checked my dashboard. It also shows that I successfully logged in. (Attaching an image with dashboard vivox login data. Red marked area is with random string.)

    Dashboard.JPG

    Now I am confused why it is working successfully without properly generated access token. Am I missing any necessary step? Is vivox somehow still generating test token if it finds invalid token internally? I am providing my code below.

    Code (CSharp):
    1. [SerializeField] private VivoxClientCredentials _credentials; //scriptable object with my dashboard credential
    2. private Client _client;
    3. private AccountId _accountId;
    4.  
    5. public async Task InitializeUnityServices()
    6. {
    7.     var options = new InitializationOptions();
    8.     options.SetVivoxCredentials(_credentials.Server, _credentials.Domain, _credentials.Issuer);
    9.     await UnityServices.InitializeAsync(options);
    10.     Debug.Log("Unity services initialized");
    11. }
    12.  
    13. public async Task Initialize()
    14. {
    15.     if(VivoxService.Instance.Client != null && VivoxService.Instance.Client.Initialized)
    16.     {
    17.         return;
    18.     }
    19.     await InitializeUnityServices();
    20.     VivoxService.Instance.Initialize();
    21.     _client = VivoxService.Instance.Client;
    22.     Debug.Log("Vivox client initialized");
    23. }
    24.  
    25. public async void LoginVivox(string userId, string username)
    26. {
    27.     try
    28.     {
    29.         if(_loginSession != null && _loginSession.State == LoginState.LoggedIn)
    30.         {
    31.             return;
    32.         }
    33.         await Initialize();
    34.         _accountId = new AccountId
    35.             (
    36.                 VivoxService.Instance.Issuer,
    37.                 userId,
    38.                 VivoxService.Instance.Domain,
    39.                 username,
    40.                 null,
    41.                 VivoxService.Instance.EnvironmentId
    42.             );
    43.          string accessToken = await GetVivoxLoginTokenFromMyServerAsync(); //My server generated token
    44.         _vivoxLogin.Login(_client.GetLoginSession(_accountId), new Uri(_credentials.Server), accessToken);
    45.     }
    46.     catch (Exception ex)
    47.     {
    48.         Debug.LogError(ex);
    49.     }
    50. }
    51.  
    52. public void Login(ILoginSession loginSession, Uri serverUri, string accessToken)
    53. {
    54.     if (loginSession == null || serverUri == null))
    55.     {
    56.         return;
    57.     }
    58.  
    59.     loginSession.PropertyChanged += LoginSession_PropertyChanged;
    60.     loginSession.BeginLogin(serverUri, accessToken , ar =>
    61.     {
    62.         try
    63.         {
    64.             loginSession.EndLogin(ar);
    65.         }
    66.         catch (Exception e)
    67.         {
    68.             // Handle error
    69.             Debug.LogError(nameof(e));
    70.             // Unbind if we failed to login.
    71.             loginSession.PropertyChanged -= LoginSession_PropertyChanged;
    72.         }
    73.     });
    74. }
    75.  
    76. private void LoginSession_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    77. {
    78.     var loginSession = (ILoginSession)sender;
    79.     if (e.PropertyName == "State")
    80.     {
    81.         switch(loginSession.State)
    82.         {
    83.             case LoginState.LoggingIn:
    84.                 Debug.Log("Trying to login vivox.");
    85.                 break;
    86.             case LoginState.LoggedIn:
    87.                 Debug.Log("Logged in to the vivox.");
    88.                 break;
    89.             case LoginState.LoggingOut:
    90.                 Debug.Log("Trying to logout vivox.");
    91.                 break;
    92.             case LoginState.LoggedOut:
    93.                 Debug.Log("Logged out of the vivox.");
    94.                 break;
    95.             default:
    96.                 Debug.Log("Something went wrong while trying to log in to the vivox.");
    97.                 break;
    98.         }
    99.     }
    100. }
    In case of "Case 2" I get "logged in to vivox." every time. I donno why. It's possible I missed something but donno what.
     
    Last edited: May 11, 2023
    augustoDebard likes this.
  2. kinoshita-hope

    kinoshita-hope

    Joined:
    Jan 20, 2023
    Posts:
    1
    I have the same issue.
    I am using vivox core sdk version 5.21.0.33641.4d38c7cc.
     
    Last edited: Oct 12, 2023
    augustoDebard likes this.