middleware JWT decoding
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
I am getting error:
from this code:
[TypeError: "spki" must be SPKI formatted string]from this code:
const organizerCookie = req.cookies.get('organizerAccessToken');
if (organizerCookie) {
try {
const publicKey = await importSPKI(process.env.JWT_TOKEN_SECRET, 'RS256');
//Verify the token
const { payload, protectedHeader } = await jwtVerify(organizerCookie, publicKey);
//Check additional claims
const { alg, type, } = protectedHeader;
if (alg !== 'RS256' || type !== 'JWT' || payload.exp < Date.now() / 1000) {
throw new Error('Invalid token claims');
}
return payload;
}
catch (error) {
return error;
}
}9 Replies
Brown bearOP
@Jboncz
So... I dont really know much about HS256 and cant find any jose documentation on how to validate using that.
This may point you in the right direction
To really test I would have to make a reporudction and work through the problems, I dont hhave time for that right now though :/
Brown bearOP
np, my string is longer than 32 letters so i dont know what to do
ill discuss the rs part with my uppers
ty
Gotcha, np. Ill check back in later