Skip to content

Commit

Permalink
🚑 oauth implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ChipWolf committed Jun 8, 2019
1 parent 13b5a09 commit 10f689c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@ fetch_fly() {

if ! [ -x $FLY ]; then
echo "Fetching fly..."
curl -SsL $insecure_arg -u "$username:$password" "$url/api/v1/cli?arch=amd64&platform=linux" -o $FLY

COOKIE_FILE="${TMP_DIR}/cookie.txt"
echo "Getting FORM token..."
FORM_TOKEN="$(curl $insecure_arg -b ${COOKIE_FILE} -c ${COOKIE_FILE} -s -L "${url}/sky/login" | \
grep -i '?req=' | cut -d '"' -f 2 | tail -n1)"
if [ -z "${FORM_TOKEN}" ];then
echo "Could not retrieve FORM token"
exit 1
fi

echo "Getting OAUTH token..."
curl -Ss $insecure_arg -o /dev/null -s -b ${COOKIE_FILE} -c ${COOKIE_FILE} -L --data-urlencode "login=${username}" \
--data-urlencode "password=${password}" "${url}${FORM_TOKEN}"
OAUTH_TOKEN=$(cat ${COOKIE_FILE} | grep 'skymarshal_auth' | grep -o 'Bearer .*$' | tr -d '"')
if [ -z "$OAUTH_TOKEN" ];then
echo "Could not retrieve OAUTH token"
exit 1
fi

curl -SsL $insecure_arg -H "Authorization: $OAUTH_TOKEN" "$url/api/v1/cli?arch=amd64&platform=linux" -o $FLY
chmod +x $FLY
fi
}
Expand Down

0 comments on commit 10f689c

Please sign in to comment.