From 10f689cbb47ae68fa5bc30f45d7dcaa938710a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chip=20Wolf=20=E2=80=AE?= Date: Sat, 8 Jun 2019 00:12:22 +0100 Subject: [PATCH] :ambulance: oauth implemented --- assets/common.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/assets/common.sh b/assets/common.sh index 621df45..e169dbd 100644 --- a/assets/common.sh +++ b/assets/common.sh @@ -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 }