Skip to content

Commit

Permalink
🚑 oauth implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ChipWolf committed Apr 27, 2020
1 parent c8ce6d1 commit d1e5f05
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,38 @@ fetch_fly() {

if ! [ -x $FLY ]; then
echo "Fetching fly..."
curl -fSsL $insecure_arg "$url/api/v1/cli?arch=amd64&platform=linux" -o "$FLY"
chmod +x "$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
}

login() {
local url="$1"
local username="$2"
local password="$3"
local team="$4"
local insecure="$5"
local target="$6"
local tried="$7"
local url=$1
local username=$2
local password=$3
local team=$4
local insecure=$5
local tried=$6
local target=main

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

0 comments on commit d1e5f05

Please sign in to comment.