Question
When trying to run verify in lambda, i get the following error:
{
"errorType": "TypeError",
"errorMessage": "JwtRsaVerifier.create is not a function",
"stack": [
"TypeError: JwtRsaVerifier.create is not a function",
" at Runtime.module.exports.verifyToken [as handler] (/var/task/authorizer.js:35:37)",
" at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
]
}
const token = 'TEST TOKENXXXXXXXXXXX';
const methodArn = event.FunctionArn;
const verifier = CognitoJwtVerifier.create({
issuer: "https://login.microsoftonline.com/XXXXXXXXXXX/v2.0", // set this to the expected "iss" claim on your JWTs
audience: "XXXXXXXXX" // set this to the expected "aud" claim on your JWTs
//jwksUri: "https://example.com/.well-known/jwks.json", // set this to the JWKS uri from your OpenID configuration
});
verifier.map((obj)=>{
console.log(obj)
})
console.log('---------',verifier)
try {
const payload = await verifier.verify(token);
console.log("Token is valid. Payload:", payload);
return callback(null, generateAuthResponse(payload.id, "Allow", methodArn));
} catch {
return callback(null, generateAuthResponse(payload.id, "Deny", methodArn));
}
Question When trying to run verify in lambda, i get the following error:
{ "errorType": "TypeError", "errorMessage": "JwtRsaVerifier.create is not a function", "stack": [ "TypeError: JwtRsaVerifier.create is not a function", " at Runtime.module.exports.verifyToken [as handler] (/var/task/authorizer.js:35:37)", " at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)" ] }
Versions
aws-jwt-verify
: 4.0.1 Node.js 20.xBelow is my authorizer.js file:
`var CognitoJwtVerifier=require("aws-jwt-verify");
function generateAuthResponse(principalId, effect, methodArn) { const policyDocument = generatePolicyDocument(effect, methodArn);
}
function generatePolicyDocument(effect, methodArn) { if (!effect || !methodArn) return null;
} module.exports.verifyToken = async (event, context, callback) => {
};`