Skip to content

Commit

Permalink
add cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
italopessoa committed Sep 21, 2024
1 parent 7540357 commit 9e9b747
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/cpf-policy-authorizer/src/handlers/hello-from-lambda.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const handler = async (event, context, callback) => {
let token = generateAccessToken({
role: ["user"]
});
return generateAuthPolicy("anom", event.routeArn, true, token);
return generateAuthPolicy(generateUniqueRandomValue(), event.routeArn, true, token);
}
};

export const generateUniqueRandomValue = () => {
return Math.random().toString(36).substr(2, 9);
};
4 changes: 2 additions & 2 deletions app/cpf-policy-authorizer/src/helpers/policyHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const generateAuthPolicy = (principalId, routeArn, accessToken) => {
try {

console.log('Method ARN: ' + routeArn);

let tmp = routeArn.split(':');
Expand All @@ -22,7 +21,8 @@ export const generateAuthPolicy = (principalId, routeArn, accessToken) => {
let authResponse = policy.build();

authResponse.context = {
accessToken: accessToken
accessToken: accessToken,
cacheKey: principalId
};
return authResponse;
}
Expand Down
1 change: 1 addition & 0 deletions modules/authenticator_agw/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ resource "aws_apigatewayv2_authorizer" "external" {
name = "cpf_authorizer"
authorizer_payload_format_version = "2.0"
authorizer_result_ttl_in_seconds = 60
identity_sources = ["$context.authorizer.cacheKey"]
enable_simple_responses = false
authorizer_uri = var.authenticator_lambda_arn
}

0 comments on commit 9e9b747

Please sign in to comment.