Skip to content

Instantly share code, notes, and snippets.

@andreaceccanti
Created December 13, 2016 13:19
Show Gist options
  • Save andreaceccanti/7d863db5ce3f43c74123a2cea8b8f9ff to your computer and use it in GitHub Desktop.
Save andreaceccanti/7d863db5ce3f43c74123a2cea8b8f9ff to your computer and use it in GitHub Desktop.
#!/bin/bash
IAM_CLIENT_ID=${IAM_CLIENT_ID:-iam-client}
IAM_CLIENT_SECRET=${IAM_CLIENT_SECRET}
IAM_TOKEN_ENDPOINT=${IAM_TOKEN_ENDPOINT:-https://iam-test.indigo-datacloud.eu/token}
if [[ -z "${IAM_CLIENT_SECRET}" ]]; then
echo "Please provide a client secret setting the IAM_CLIENT_SECRET env variable."
exit 1;
fi
if [[ -z ${IAM_USER} ]]; then
read -p "Username: " IAM_USER
fi
echo -ne "Password:"
read -s IAM_PASSWORD
echo
result=$(curl -s -L \
-d client_id=${IAM_CLIENT_ID} \
-d client_secret=${IAM_CLIENT_SECRET} \
-d grant_type=password \
-d username=${IAM_USER} \
-d password=${IAM_PASSWORD} \
-d scope="openid profile email" \
${IAM_TOKEN_ENDPOINT})
if [[ $? != 0 ]]; then
echo "Error!"
echo $result
exit 1
fi
access_token=$(echo $result | jq -r .access_token)
echo "export IAM_ACCESS_TOKEN=\"${access_token}\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment