基于接口实现的令牌生成
How to generate access tokens using an interface implementation.
阅读时间2 分钟最后更新于 13 天前
如果要控制 Vivox 访问令牌 (VAT) 的生成方式,请创建一个实现 Vivox SDK 的
IVivoxTokenProviderVivoxService.Instance.SetTokenProviderIVivoxTokenProvider.GetTokenAsyncIVivoxTokenProvider.GetTokenAsyncIVivoxTokenProvider.GetTokenAsync订阅
在登录您的用户之前,您必须使用以下方法注册您的IVivoxTokenProviderVivoxService.Instance.SetTokenProvider(new CustomTokenProvider());
获取令牌
应使用覆盖的方法中提供的所有参数(即使有些参数为空)创建有效负载,并将有效负载发送到您的安全服务器以生成您的 Vivox 访问令牌。最佳做法是发送所有参数;仅返回有效负载所需的内容。使用有效负载作为GetTokenAsync如需了解有关此特定流程的更多详细信息,请参阅使用 Vivox 访问令牌登录。 要了解有关生成服务器端令牌的更多信息,请参阅在安全服务器上生成令牌。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 }}