I am facing CORS issue when authoriser invalidate token, I guess because lack of header “Access-Control-Allow-Credentials”.
- How can i resolve this issue?
- how can i add custom headers in authorizer response?
- Can i add custom message in authrizer response?
Authorizer code is below :
function generateAuthResponse(principalId, effect, methodArn) {
const policyDocument = generatePolicyDocument(effect, methodArn);
console.log(‘8 - generateAuthResposne’, principalId)return {
principalId, policyDocument
};
}
function generatePolicyDocument(effect, methodArn) {
if (!effect || !methodArn) return null;
const policyDocument = {
Version: "2012-10-17", Statement: [ { Action: "execute-api:Invoke", Effect: effect, Resource: methodArn } ]
};
return policyDocument;
}
module.exports.handler = async function verifyToken(event, context, callback) {
const token = event.authorizationToken;
const methodArn = event.methodArn;
if (!token || !methodArn) return callback(null, “Unauthorized”);
try {
const user = await getUserFromToken(token) // call token func
if (user && user.userId) {
return callback(null, generateAuthResponse(user.userId, “Allow”, methodArn));
} else {
return callback(null, generateAuthResponse(‘Inalid user’, “Deny”, methodArn));
}
} catch(error) {
return callback(null, generateAuthResponse(error.message, “Deny”, methodArn));}
};