Hello there! I'm currently in need of assistance with generating JWT tokens that include three headers: alg, kid, and typ. The format I am looking for is as follows:
{
"alg": "RS256",
"kid": "vpaas-magic-cookie-1fc542a3e4414a44b2611668195e2bfe/4f4910",
"typ": "JWT"
}
You can find more detailed information about this process on this page.
It's important to note that JWT tokens have an expiration time frame of a few hours. Due to this, I am exploring ways to generate these tokens directly within my code.
Below is a snippet of my JavaScript code where I insert the JWT token into the options list for authentication purposes:
var options = {
roomName: "vpaas-magic-cookie-secretKey/Room123",
jwt: 'JWTTOKEN',
,
Based on my research on jwt.io, it seems that generating tokens involves using the HS256 algorithm. Could someone guide me through the steps to achieve this using JavaScript?
In response to another user's answer, I made some adjustments to their code and now I am able to generate part of the JWT token. I am comparing this generated token with one obtained from the Jaas.8x8 server.
<script>
const HMACSHA256 = (stringToSign, secret) => "not_implemented"
// The header typically consists of two parts:
// the type of the token, which is JWT, and the signing algorithm being used,
// such as HMAC SHA256 or RSA.
const header = {
"kid": "vpaas-magic-cookie-07fabede3674457a84c95fsecretcode/myroom001",
"alg": "RS256",
"typ": "JWT"
}
const encodedHeaders = btoa(JSON.stringify(header))
// create the signature part you have to take the encoded header,
// the encoded payload, a secret, the algorithm specified in the header,
// and sign that.
const signature = HMACSHA256(`${encodedHeaders}`, "mysecret")
console.log(`${encodedHeaders}.${signature}`)
</script>
The token generated from the above code snippet looks like this:
eyJraWQiOiJ2cGFhcy1tYWdpYy1jb29raWUtMDdmYWJlZGUzNjc0NDU3YTg0Yzk1ZmE4MGIxNGY1ZDcvVGVzdFJhdW0wMDEiLCJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.not_implemented
When compared to a sample token obtained online, it seems that only a portion of the token matches up. Could this discrepancy be related to the 'mysecret' parameter? What exactly does 'mysecret' signify?