Created
July 22, 2018 06:57
-
-
Save mousavian/a325be757f83ab17476ff11df6c3c960 to your computer and use it in GitHub Desktop.
Akamai Open API Curl command example
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
#!/bin/bash | |
readonly CLIENT_SECRET="" | |
readonly CLIENT_TOKEN="" | |
readonly ACCESS_TOKEN="" | |
readonly HOST="" | |
readonly REQUEST_PATH="/papi/v1/search/find-by-value" | |
readonly REQUEST_BODY='{"propertyName":"myProperty"}' | |
readonly REQUEST_TYPE="POST" | |
readonly TIMESTAMP=$(date -u +%Y%m%dT%H:%M:%S+0000) | |
readonly NONCE=$(python -c 'import uuid; print uuid.uuid1()') | |
function join_by { perl -e '$s = shift @ARGV; print join($s, @ARGV);' "$@"; } | |
Authorization="EG1-HMAC-SHA256 client_token=${CLIENT_TOKEN};access_token=${ACCESS_TOKEN};timestamp=${TIMESTAMP};nonce=${NONCE};" | |
signingKey=$(echo -en "$TIMESTAMP" | openssl dgst -binary -sha256 -hmac "$CLIENT_SECRET" | base64 ) | |
contentHash=$(echo -en "${REQUEST_BODY/ //g}" | shasum -a 256 --binary | cut -d " " -f 1 | xxd -r -p | base64) | |
dataToSign=( | |
"POST" | |
"https" | |
"$HOST" | |
"$REQUEST_PATH" | |
"" | |
"$contentHash" | |
"$Authorization" | |
) | |
dataToHash=$(join_by '\t' "${dataToSign[@]}") | |
hashedData=$(echo -en "$dataToHash" | openssl dgst -binary -sha256 -hmac "$signingKey" | base64) | |
curl -i -X"$REQUEST_TYPE" \ | |
"https://${HOST}${REQUEST_PATH}" \ | |
-H "Authorization: ${Authorization}signature=${hashedData}" \ | |
-H "Content-Type: application/json" \ | |
-d "${REQUEST_BODY}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to their documentation here:
https://developer.akamai.com/introduction/Client_Auth.html