Generate Authentication Token from C# server - fail when trying to use this generated C# signature on client.join()

I am trying to generate an authentication token from C# that I can pass into the client side.

I have tried couple ways to generate the auth token using C#. Can you please let me know what’s wrong the following snippet C# codes?

PART I

    var signature = string.Empty;

                var iat = Math.Round(GetTime() / 1000);
                var exp = iat + 7200;

                var claims = new List<Claim>
                {
                    new Claim("app_key", zoomInfo.SdkKey),
                    new Claim("iat", iat.ToString(CultureInfo.InvariantCulture)),
                    new Claim("exp", exp.ToString(CultureInfo.InvariantCulture)),
                    new Claim("tpc", topic),
                    new Claim("pwd", string.Empty)
                };

                var key = zoomInfo.SdkSecret;
                var encoding = new ASCIIEncoding();
                byte[] keyByte = encoding.GetBytes(key);
                var securityKey = new SymmetricSecurityKey(keyByte);
                var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

                var secToken = new JwtSecurityToken(
                    zoomInfo.SdkKey,
                    null,
                    claims,
                    DateTime.UtcNow,
                    DateTime.UtcNow.AddHours(10),
                    credentials);

                var handler = new JwtSecurityTokenHandler();
                signature = handler.WriteToken(secToken);

PART II => THIS WILL CREATE CORS ISSUE

    var key = zoomInfo.SdkSecret;
                var encoding = new ASCIIEncoding();
                byte[] keyByte = encoding.GetBytes(key);
                var securityKey = new SymmetricSecurityKey(keyByte);
                var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
                var now = DateTime.UtcNow;
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Issuer = zoomInfo.SdkKey,
                    Expires = now.AddHours(1),
                    SigningCredentials = credentials,
                    Claims = new Dictionary<string, object>
                    {
                        {"app_key", zoomInfo.SdkKey},
                        {"iat", iat.ToString(CultureInfo.InvariantCulture)},
                        {"exp", exp.ToString(CultureInfo.InvariantCulture)},
                        {"tpc", topic},
                        {"pwd", string.Empty}
                    }
                };

                var handler = new JwtSecurityTokenHandler();
                var token = handler.CreateJwtSecurityToken(tokenDescriptor);
                signature = handler.WriteToken(token);

I need to get that signature so that I can pass the signature into the following

client.join(
  topic,
  signature,
  userName,
  password,
).then(() => {
  console.log('Join meeting success');
}).catch((error) => {
  console.error(error);
});

Thanks

Hey @joecodingjourney_1 ,

What is the error message you are getting? Also, if you got this code snippet from our docs, can you please share the link so we can investigate?

Thanks,
Tommy

Hi Tommy, I figured that authentication stuff.

However I got another question about rendering the canvas whenever there are participant join the meeting.

So, if we have multiple participants trying to join the meeting, do we need to create multiple canvas for the video rendering?

Or, all of those participants can share a canvas?

Thanks,
-Joseph

Hey @joecodingjourney_1 ,
You can render multiple videos in one canvas, use width, height, x, and y parameters of renderVideo method to specify the position of video in the canvas.

Thanks
Vic

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.