Last active
September 7, 2018 22:28
-
-
Save dchw/3ec44e5b7e7ef8bb6e484483dcbea560 to your computer and use it in GitHub Desktop.
Get a Spinnaker session cookie when using MS OAuth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Authorizing with MS" | |
curl -s --request POST \ | |
--url https://login.microsoftonline.com/$AZURE_TENANT_ID/oauth2/token \ | |
--header 'content-type: application/x-www-form-urlencoded' \ | |
--data-urlencode "grant_type=password" \ | |
--data-urlencode "resource=https://graph.windows.net" \ | |
--data-urlencode "client_id=$SPINNAKER_CLIENT_ID" \ | |
--data-urlencode "password=$BUILD_PASSWORD" \ | |
--data-urlencode "client_secret=$SPINNAKER_CLIENT_SECRET" \ | |
--data-urlencode "username=$BUILD_USER" \ | |
> jwt.txt | |
echo "Extracting MS Access Token" | |
accessToken=$(cat jwt.txt | jq -r .access_token) | |
echo "Pinging Spinnaker with MS Access Token" | |
curl -s -c cookies.jar -L --request GET \ | |
--url $SPINNAKER_API_URL/credentials \ | |
--header "authorization: Bearer $accessToken" \ | |
> /dev/null | |
apiSession=$(awk '/SESSION/ { print $NF }' cookies.jar) | |
echo "Using Spinnaker session: $apiSession" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment