【问题标题】:Web Agora.io DYNAMIC_KEY_EXPIREDWeb Agora.io DYNAMIC_KEY_EXPIRED
【发布时间】:2020-06-25 09:33:17
【问题描述】:

我正在使用 c# 和 mvc。

我使用此代码生成令牌并成功生成。但是在使用 .join() 加入频道时生成令牌后,它会返回 DYNAMIC_KEY_EXPIRED。 我使用了“AgoraRTCSDK-3.1.0.js”

我使用https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/csharp生成动态令牌

如果有人对 Agora.io 有经验,请帮助我。

示例代码是..

AccessToken token = new AccessToken(apiKey, appCertificate, channelName, "0");
token.addPrivilege(Privileges.kJoinChannel, _expiredTs);
token.addPrivilege(Privileges.kPublishAudioStream, _expiredTs);
token.addPrivilege(Privileges.kPublishVideoStream, _expiredTs);
string strToken = token.build();

public string build()
    {
        this._messageRawContent = Utils.pack(this.message);
        this._signature = generateSignature(_appCertificate
                , _appId
                , _channelName
                , _uid
                , _messageRawContent);

        this._crcChannelName = Crc32CAlgorithm.Compute(this._channelName.GetByteArray());
        this._crcUid = Crc32CAlgorithm.Compute(this._uid.GetByteArray());

        PackContent packContent = new PackContent(_signature, _crcChannelName, _crcUid, this._messageRawContent);
        byte[] content = Utils.pack(packContent);
        return getVersion() + this._appId + Utils.base64Encode(content);
    }

【问题讨论】:

  • 您为令牌设置的到期时间是多少?
  • uint _expiredTs = 0;

标签: c# agora.io agora-web-sdk-ng


【解决方案1】:

每当您为 Agora 应用程序生成令牌时,您需要记住过期时间是按时间戳计算的(自 1970 年以来的时间),因此您需要确保将过期时间设置为 currentTime + expirationTimeInSeconds

在上面的示例中,您将过期时间传递为​​ 0,这会生成一个已被视为过期的令牌。

考虑使用:

  // set a expiration time of 1 hour in seconds
  let expireTime = 3600;

  // calculate current time in seconds
  const currentTime = Math.floor(Date.now() / 1000);

  // calculate privilege expire time
  const privilegeExpireTime = currentTime + expireTime;

【讨论】:

  • 我按照您的指示进行操作,但在生成有效令牌时仍然遇到问题....您知道 agora io 是否已更改任何内容吗?谢谢
  • 什么都没有改变,同样的逻辑仍然适用。我建议使用您可以提供的任何代码提出一个新问题,以便团队可以帮助您。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多