Skip to content

Instantly share code, notes, and snippets.

@mousavian
Created July 22, 2018 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mousavian/a325be757f83ab17476ff11df6c3c960 to your computer and use it in GitHub Desktop.
Save mousavian/a325be757f83ab17476ff11df6c3c960 to your computer and use it in GitHub Desktop.
Akamai Open API Curl command example
#!/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}"
@mousavian
Copy link
Author

According to their documentation here:
https://developer.akamai.com/introduction/Client_Auth.html

@vgajend
Copy link

vgajend commented Jun 8, 2020

@mousavian is this work

@Aduril
Copy link

Aduril commented Jan 18, 2024

You saved us a lot of headache with this script! Thanks a lot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment