I am creating a JWT token authorizer and I am nearly their I think, I just am getting an error when testing it.
So I created a Lambda token authorizer which will authorize a token on an incoming request to the gateway.
Here is the code:
const blahJWT = require("@custom/blah/authentication/blah");
exports.handler = async (event, context, callback) => {
try {
let token = extractTokenFromHeader(event) || '';
const webAuth = new blahJWT();
await webAuth.authenticateWebToken(token);
callback(null, 'Allow');
}
catch (e) {
console.log(e);
// return {body: "Unauthorized", statusCode: 401};
callback('Unauthorized');
}
};
function extractTokenFromHeader(e) {
console.log(JSON.stringify(e));
console.log(e.authorizationToken);
if (e.authorizationToken && e.authorizationToken.split(' ')[0] === 'Bearer') {
return e.authorizationToken.split(' ')[1];
}
else {
return e.authorizationToken;
}
}
However when I pass in a valid token through the api-gateway tester I get the following error:
Tue Sep 13 23:01:46 UTC 2022 : Authorizer result body before parsing: "Allow"
Tue Sep 13 23:01:46 UTC 2022 : Execution failed due to configuration error: Invalid JSON in response: Cannot construct instance of `com.amazonaws.backplane.executioncore.frontend.authorizer.CustomAuthResponse` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Allow')
Tue Sep 13 23:01:46 UTC 2022 : AuthorizerConfigurationException
I am wondering if anyone can help solve this?
Thanks