I am trying to use OAuth 1.0 in Bash script and I am getting error “The signature is invalid. Verify and try again”. Can someone please let me know how to generate valid signature using bash. I have gone through almost all the post on StackExchange, but could not find any example in bash. Below is my code
#!/bin/bash
CONSUMER_KEY="my_consumer_key"
CONSUMER_SECRET="my_consumer_secret"
TOKEN="my_token"
TOKEN_SECRET="my_token_secret"
URL="https://<Magento_Store>/rest/default/V1/products/base-prices"
NONCE=$(date +%s%N | sha256sum | base64 | head -c 32 ; echo)
TIMESTAMP=$(date +%s)
PARAMS="oauth_consumer_key=$CONSUMER_KEY&oauth_nonce=$NONCE&oauth_signature_method=HMAC-SHA1&oauth_timestamp=$TIMESTAMP&oauth_token=$TOKEN&oauth_version=1.0"
BASE_STRING="POST&$(echo $URL | sed -e 's/(.*):////' -e 's/?.*//' -e 's/(.*)/L1/' -e 's///%2F/g' -e 's/:/%3A/g')&$(echo $PARAMS | sed -e 's/&/%26/g' -e 's/=/%3D/g')"
SIGNATURE=$(echo -n "$BASE_STRING" | openssl dgst -sha1 -hmac "$CONSUMER_SECRET&$TOKEN_SECRET" -binary | base64)
SIGNATURE1=$(echo $SIGNATURE | sed -e 's/+/%2B/g' -e 's///%2F/g' -e 's/=/%3D/g')
echo $SIGNATURE1
curl -v -X POST
$URL
-H "Authorization: OAuth oauth_consumer_key="$CONSUMER_KEY",oauth_token="$TOKEN",oauth_signature_method="HMAC-SHA256",oauth_timestamp="$TIMESTAMP",oauth_nonce="$NONCE",oauth_version="1.0",oauth_signature="$SIGNATURE1""
-H 'Content-Type: application/json'
-H 'cache-control: no-cache'
-d '{
"prices": [
{
"price": 250,
"store_id": 0,
"sku": "101180600131205",
"extension_attributes": {}
}
]
} '