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