login.sh 907 B

12345678910111213141516171819202122232425
  1. #! /bin/bash
  2. pushd terraform
  3. CLIENT_ID=$( terraform output --raw cognito_client_id )
  4. ENDPOINT=$( terraform output --raw test_api_endpoint )
  5. RAW=$( curl --location --request POST 'https://cognito-idp.us-east-2.amazonaws.com' \
  6. --header 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
  7. --header 'Content-Type: application/x-amz-json-1.1' \
  8. --data-raw '{
  9. "AuthParameters" : {
  10. "USERNAME" : "fdamstra",
  11. "PASSWORD" : "Bluem00n"
  12. },
  13. "AuthFlow" : "USER_PASSWORD_AUTH",
  14. "ClientId" : "'${CLIENT_ID}'"
  15. }'
  16. )
  17. ACCESS_TOKEN=$( echo "$RAW" | jq '.AuthenticationResult.AccessToken' -r )
  18. echo RUN:
  19. echo \ \ \ \ ACCESS_TOKEN="${ACCESS_TOKEN}"
  20. echo \ \ \ \ curl --request GET \'"${ENDPOINT}"/example\' --header \"Authorization: Bearer \${ACCESS_TOKEN}\"
  21. popd