Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Last active April 12, 2019 09:56
Show Gist options
  • Save chgeuer/e4e343f290375ac437e9eceafb6fb102 to your computer and use it in GitHub Desktop.
Save chgeuer/e4e343f290375ac437e9eceafb6fb102 to your computer and use it in GitHub Desktop.
#!/bin/bash
aadTenant="sapdevchallenge.onmicrosoft.com"
resource="https://sapteameagleui.blob.core.windows.net"
container="tobias"
blob="test"
deviceResponse="$(curl \
--silent \
--request POST \
--data-urlencode client_id=04b07795-8ddb-461a-bbee-02f9e1bf7b46 \
--data-urlencode resource=${resource} \
https://login.microsoftonline.com/${aadTenant}/oauth2/devicecode?api-version=1.0
)"
device_code="$(echo "${deviceResponse}" | jq -r ".device_code")"
sleep_duration="$(echo "${deviceResponse}" | jq -r ".interval")"
access_token=""
while [ "${access_token}" == "" ]
do
tokenResponse="$(curl \
--silent \
--request POST \
--data-urlencode "grant_type=device_code" \
--data-urlencode "client_id=04b07795-8ddb-461a-bbee-02f9e1bf7b46" \
--data-urlencode "resource=${resource}" \
--data-urlencode "code=${device_code}" \
"https://login.microsoftonline.com/common/oauth2/token")"
if [ "$(echo "${tokenResponse}" | jq -r ".error")" == "authorization_pending" ]; then
echo "$(echo "${deviceResponse}" | jq -r ".message")"
sleep "${sleep_duration}"
else
access_token="$(echo "${tokenResponse}" | jq -r ".access_token")"
echo "User authenticated"
fi
done
curl --silent --get \
--header "Authorization: Bearer ${access_token}" \
--header "x-ms-version: 2018-03-28" \
"${resource}/$container/$blob"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment