
Extract a part of JWT token from the Authorization header and pass it on to the backend integrations as a separate header
#set($authHeaderValue = $input.params().header.get('Authorization'))
#if($authHeaderValue.startsWith('Bearer '))
#set($clientId = $authHeaderValue.substring(7))
#set($context.requestOverrideConfiguration.headers.clientId = $clientId)
$util.toJson($input.json('$'))
#else
$util.badRequest("Missing or invalid 'Authorization' header")
#end
{
"method": "$context.httpMethod",
"body" : $input.json('$'),
"headers": {
"clientId": "$util.escapeJavaScript($clientId)"
}
}
#set($authHeaderValue = $input.params().header.get('Authorization'))
#if($authHeaderValue.startsWith('Bearer '))
#set($clientId = $authHeaderValue.substring(7))
#set($allHeaders = $input.params().header)
#set($entry = {})
$util.qr($allHeaders.put('clientId', $clientId))
$util.toJson($input.json('$'))
#else
$util.badRequest("Missing or invalid 'Authorization' header")
#end
{
"method": "$context.httpMethod",
"body" : $input.json('$'),
"headers": "$util.escapeJavaScript($allHeaders)"
}
curl --location 'https://abcde1234.execute-api.us-east-1.amazonaws.com/Stage/Resource-1’ \
--header 'Authorization: Bearer a1b2c3d4e5f6g7.h8i9j0k1l2m3n4o5p6.q7r8s9t0u1v2w3x4y5z' \
--header 'Cloud: AWS' \
--header 'Content-Type: application/json' \
--data '{"Condition”:”Check the headers”}’