login.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #! /bin/bash
  2. pushd terraform > /dev/null
  3. CLIENT_ID=$( terraform output --raw cognito_client_id )
  4. ENDPOINT=$( terraform output --raw test_api_endpoint )
  5. popd > /dev/null
  6. RAW=$( curl --silent --show-error --location --request POST 'https://cognito-idp.us-east-2.amazonaws.com' \
  7. --header 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
  8. --header 'Content-Type: application/x-amz-json-1.1' \
  9. --data-raw '{
  10. "AuthParameters" : {
  11. "USERNAME" : "fdamstra",
  12. "PASSWORD" : "Bluem00n"
  13. },
  14. "AuthFlow" : "USER_PASSWORD_AUTH",
  15. "ClientId" : "'${CLIENT_ID}'"
  16. }'
  17. )
  18. ACCESS_TOKEN=$( echo "$RAW" | jq '.AuthenticationResult.AccessToken' -r )
  19. echo ACCESS_TOKEN=\""${ACCESS_TOKEN}"\"
  20. echo ""
  21. echo ENDPOINT=\""${ENDPOINT}"\"
  22. echo ""
  23. echo "Calls:"
  24. echo " "curl --request GET \'"${ENDPOINT}"/example\' --header \"Authorization: Bearer \${ACCESS_TOKEN}\"
  25. echo " "curl --request GET \'"${ENDPOINT}"/echo\' --header \"Authorization: Bearer \${ACCESS_TOKEN}\" \| jq
  26. echo " "
  27. echo view the comments for more.
  28. # When json encoded:
  29. # curl -d '{"fredwasalsohere": "true"}' -H "Content-Type: application/json" --request POST "${ENDPOINT}"'/echo?fredwashere=true' --header "Authorization: Bearer ${ACCESS_TOKEN}" | jq '.event.body | fromjson'
  30. #
  31. # When not:
  32. # curl -d "fredwasalsohere=2" --request POST ${ENDPOINT}"'/echo?fredwashere=true' --header "Authorization: Bearer ${ACCESS_TOKEN}" | jq -r .event.body | base64 -d