123456789101112131415161718192021222324252627282930313233343536 |
- #! /bin/bash
- pushd terraform > /dev/null
- CLIENT_ID=$( terraform output --raw cognito_client_id )
- ENDPOINT=$( terraform output --raw test_api_endpoint )
- popd > /dev/null
- RAW=$( curl --silent --show-error --location --request POST 'https://cognito-idp.us-east-2.amazonaws.com' \
- --header 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
- --header 'Content-Type: application/x-amz-json-1.1' \
- --data-raw '{
- "AuthParameters" : {
- "USERNAME" : "fdamstra",
- "PASSWORD" : "Bluem00n"
- },
- "AuthFlow" : "USER_PASSWORD_AUTH",
- "ClientId" : "'${CLIENT_ID}'"
- }'
- )
- ACCESS_TOKEN=$( echo "$RAW" | jq '.AuthenticationResult.AccessToken' -r )
- echo ACCESS_TOKEN=\""${ACCESS_TOKEN}"\"
- echo ""
- echo ENDPOINT=\""${ENDPOINT}"\"
- echo ""
- echo "Calls:"
- echo " "curl --request GET \'"${ENDPOINT}"/example\' --header \"Authorization: Bearer \${ACCESS_TOKEN}\"
- echo " "curl --request GET \'"${ENDPOINT}"/echo\' --header \"Authorization: Bearer \${ACCESS_TOKEN}\" \| jq
- echo " "
- echo view the comments for more.
- # When json encoded:
- # curl -d '{"fredwasalsohere": "true"}' -H "Content-Type: application/json" --request POST "${ENDPOINT}"'/echo?fredwashere=true' --header "Authorization: Bearer ${ACCESS_TOKEN}" | jq '.event.body | fromjson'
- #
- # When not:
- # curl -d "fredwasalsohere=2" --request POST ${ENDPOINT}"'/echo?fredwashere=true' --header "Authorization: Bearer ${ACCESS_TOKEN}" | jq -r .event.body | base64 -d
|