Need help for agora.io when need to generate token

45 Views Asked by At

I'm trying to Secure authentication with tokens following system flow here https://docs.agora.io/en/video-calling/get-started/authentication-workflow?platform=flutter

I did research then I found this useful article here: https://www.agora.io/en/blog/how-to-build-a-token-server-for-agora-applications-using-nodejs/

I did my own version by using nestjs

try {
  let expireTime = expiry;
  if (!expireTime || expireTime === '') {
    expireTime = 3600;
  } else {
    expireTime = parseInt(expireTime, 10);
  }
  const currentTime = Math.floor(Date.now() / 1000);
  const privilegeExpireTime = currentTime + expireTime;

  if (!uid) {
    throw new BadRequestException('uid is required');
  }

  if (!channelName) {
    throw new BadRequestException('channel is required');
  }

  // get role
  const _role = RtcRole.PUBLISHER;

  const token = RtcTokenBuilder.buildTokenWithUid(
    process.env.APP_ID,
    process.env.APP_CERTIFICATE,
    channelName,
    uid,
    _role,
    privilegeExpireTime,
    privilegeExpireTime,
  );

  return new ResponseSuccess('LIVE.RTC_TOKEN', token);
} catch (error) {
  return new ResponseError(error, null);
}

to generate a token I request my API with these parameters

{
"uid": "0",
"channelName": "rtc",
}

yes, it works well I tested with demo web here https://webdemo.agora.io/basicVideoCall/index.html

and then I try to change "uid" to another not "0" Whenever I try to use the token it doesn't work at all.

after many attempts to solve issues and try to understand how "agora-token" and "agora-access-token" lib work (cannot find an API doc to read or even a clear explanation), I use "uid: 0" everywhere but when I use in flutter "I got the error: Remote uid can not be null or 0"

Help me please, I need an explanation of how it works and how to implement a token server in the right way.

0

There are 0 best solutions below