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 5f78dc7
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions 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 All @@ -23,7 +42,7 @@ login() {
local team=$4
local insecure=$5
local tried=$6
local target=$7
local target=main

local insecure_arg=""
test "$insecure" = "true" && insecure_arg="--insecure"
Expand Down

0 comments on commit 5f78dc7

Please sign in to comment.