tharak#3
tharak#312mo ago

jwt generation and verification

jwt verification(using JOSE package) is working perfectly only when i have set b64 parameter inside the setProtectHeader to true, why do i need to set that parameter what was the difference in JWT generated with and without b64 parameter
1 Reply
tharak#3
tharak#312mo ago
Here is the sample code of how i was generating and verifying JWT
import { generateSecret } from 'https://deno.land/x/jose@v4.14.4/key/generate_secret.ts'; import { SignJWT } from 'https://deno.land/x/jose@v4.14.4/jwt/sign.ts'; import { jwtVerify } from 'https://deno.land/x/jose@v4.14.4/jwt/verify.ts'; let payload = { name: 'tharak' } let secretKey = await generateSecret('HS512') let JWT_TOKEN = await new SignJWT(payload) .setProtectedHeader({ alg: 'HS512', typ: "JWT" }) .setIssuer('Deno') .setAudience('Angular') .setExpirationTime('2h') .sign(secretKey) let verified_JWT = await jwtVerify(JWT_TOKEN , secretKey)
This throws me some error, but when i have given the b64 param set to true, .setProtectedHeader({ b64: true, alg: 'HS512', typ: "JWT" }) i was able to get the verified token details but why do i need to set b64 ? i should be able to verify the token without setting the b64 as well. it would be great if anyone could helpme of what exactly happening at the SignJWT