I would like to know how to delete a message on Azure Storage Queue. Currently I keep getting the following error.
<code><?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:47de86b5-3003-004d-0fc0-dd56e6000000
Time:2024-07-24T11:56:26.1466778Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request '<signature>' is not the same as any computed signature. Server used following string to sign: 'DELETE
x-ms-date:Wed, 24 Jul 2024 11:56:25 GMT
x-ms-version:2016-05-31
/gildedhonordev/ghmatchedtickets/messages/<messageid>'.</AuthenticationErrorDetail></Error>
</code>
<code><?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:47de86b5-3003-004d-0fc0-dd56e6000000
Time:2024-07-24T11:56:26.1466778Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request '<signature>' is not the same as any computed signature. Server used following string to sign: 'DELETE
x-ms-date:Wed, 24 Jul 2024 11:56:25 GMT
x-ms-version:2016-05-31
/gildedhonordev/ghmatchedtickets/messages/<messageid>'.</AuthenticationErrorDetail></Error>
</code>
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:47de86b5-3003-004d-0fc0-dd56e6000000
Time:2024-07-24T11:56:26.1466778Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request '<signature>' is not the same as any computed signature. Server used following string to sign: 'DELETE
x-ms-date:Wed, 24 Jul 2024 11:56:25 GMT
x-ms-version:2016-05-31
/gildedhonordev/ghmatchedtickets/messages/<messageid>'.</AuthenticationErrorDetail></Error>
Using this page as guidance, I have created a function that successfully get the queued message. However, the same method keeps failing at the Authorization when I want to delete a message.
Below are my codes:
<code>get_queued_message() {
DATE_ISO=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
VERSION="2016-05-31"
HEADER_RESOURCE="x-ms-date:$DATE_ISOnx-ms-version:$VERSION"
URL_RESOURCE="/$STORAGE_ACC/$QUEUE_NAME/messages"
STRING_TO_SIGN="GETnnnnnnnnnnnn$HEADER_RESOURCEn$URL_RESOURCE"
DECODED_KEY="$(echo -n "$STORAGE_KEY" | base64 -d -w0 | xxd -p -c256)"
SIGN=$(printf "$STRING_TO_SIGN" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$DECODED_KEY" -binary | base64 -w0)
RET=$(curl -X GET
-H "x-ms-date:$DATE_ISO"
-H "x-ms-version:$VERSION"
-H "Authorization: SharedKey $STORAGE_ACC:$SIGN"
-H "Content-Length:0"
"https://$STORAGE_ACC.queue.core.windows.net/$QUEUE_NAME/messages")
MESSAGE=$(echo "$RET" | grep -oP '<MessageText>K[^<]+')
MESSAGE_ID=$(echo "$RET" | grep -oP '<MessageId>K[^<]+')
POP_RECEIPT=$(echo "$RET" | grep -oP '<PopReceipt>K[^<]+')
}
delete_queued_message() {
DATE_ISO=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
VERSION="2016-05-31"
HEADER_RESOURCE="x-ms-date:$DATE_ISOnx-ms-version:$VERSION"
URL_RESOURCE="/$STORAGE_ACC/$QUEUE_NAME/messages/$MESSAGE_ID?popreceipt=$POP_RECEIPT"
STRING_TO_SIGN="DELETEnnnnnnnnnnnn$HEADER_RESOURCEn$URL_RESOURCE"
DECODED_KEY="$(echo -n "$STORAGE_KEY" | base64 -d -w0 | xxd -p -c256)"
SIGN=$(printf "$STRING_TO_SIGN" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$DECODED_KEY" -binary | base64 -w0)
curl -X DELETE
-H "x-ms-date:$DATE_ISO"
-H "x-ms-version:$VERSION"
-H "Authorization: SharedKey $STORAGE_ACC:$SIGN"
"https://$STORAGE_ACC.queue.core.windows.net/$QUEUE_NAME/messages/$MESSAGE_ID?popreceipt=$POP_RECEIPT"
}
</code>
<code>get_queued_message() {
DATE_ISO=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
VERSION="2016-05-31"
HEADER_RESOURCE="x-ms-date:$DATE_ISOnx-ms-version:$VERSION"
URL_RESOURCE="/$STORAGE_ACC/$QUEUE_NAME/messages"
STRING_TO_SIGN="GETnnnnnnnnnnnn$HEADER_RESOURCEn$URL_RESOURCE"
DECODED_KEY="$(echo -n "$STORAGE_KEY" | base64 -d -w0 | xxd -p -c256)"
SIGN=$(printf "$STRING_TO_SIGN" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$DECODED_KEY" -binary | base64 -w0)
RET=$(curl -X GET
-H "x-ms-date:$DATE_ISO"
-H "x-ms-version:$VERSION"
-H "Authorization: SharedKey $STORAGE_ACC:$SIGN"
-H "Content-Length:0"
"https://$STORAGE_ACC.queue.core.windows.net/$QUEUE_NAME/messages")
MESSAGE=$(echo "$RET" | grep -oP '<MessageText>K[^<]+')
MESSAGE_ID=$(echo "$RET" | grep -oP '<MessageId>K[^<]+')
POP_RECEIPT=$(echo "$RET" | grep -oP '<PopReceipt>K[^<]+')
}
delete_queued_message() {
DATE_ISO=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
VERSION="2016-05-31"
HEADER_RESOURCE="x-ms-date:$DATE_ISOnx-ms-version:$VERSION"
URL_RESOURCE="/$STORAGE_ACC/$QUEUE_NAME/messages/$MESSAGE_ID?popreceipt=$POP_RECEIPT"
STRING_TO_SIGN="DELETEnnnnnnnnnnnn$HEADER_RESOURCEn$URL_RESOURCE"
DECODED_KEY="$(echo -n "$STORAGE_KEY" | base64 -d -w0 | xxd -p -c256)"
SIGN=$(printf "$STRING_TO_SIGN" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$DECODED_KEY" -binary | base64 -w0)
curl -X DELETE
-H "x-ms-date:$DATE_ISO"
-H "x-ms-version:$VERSION"
-H "Authorization: SharedKey $STORAGE_ACC:$SIGN"
"https://$STORAGE_ACC.queue.core.windows.net/$QUEUE_NAME/messages/$MESSAGE_ID?popreceipt=$POP_RECEIPT"
}
</code>
get_queued_message() {
DATE_ISO=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
VERSION="2016-05-31"
HEADER_RESOURCE="x-ms-date:$DATE_ISOnx-ms-version:$VERSION"
URL_RESOURCE="/$STORAGE_ACC/$QUEUE_NAME/messages"
STRING_TO_SIGN="GETnnnnnnnnnnnn$HEADER_RESOURCEn$URL_RESOURCE"
DECODED_KEY="$(echo -n "$STORAGE_KEY" | base64 -d -w0 | xxd -p -c256)"
SIGN=$(printf "$STRING_TO_SIGN" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$DECODED_KEY" -binary | base64 -w0)
RET=$(curl -X GET
-H "x-ms-date:$DATE_ISO"
-H "x-ms-version:$VERSION"
-H "Authorization: SharedKey $STORAGE_ACC:$SIGN"
-H "Content-Length:0"
"https://$STORAGE_ACC.queue.core.windows.net/$QUEUE_NAME/messages")
MESSAGE=$(echo "$RET" | grep -oP '<MessageText>K[^<]+')
MESSAGE_ID=$(echo "$RET" | grep -oP '<MessageId>K[^<]+')
POP_RECEIPT=$(echo "$RET" | grep -oP '<PopReceipt>K[^<]+')
}
delete_queued_message() {
DATE_ISO=$(TZ=GMT date "+%a, %d %h %Y %H:%M:%S %Z")
VERSION="2016-05-31"
HEADER_RESOURCE="x-ms-date:$DATE_ISOnx-ms-version:$VERSION"
URL_RESOURCE="/$STORAGE_ACC/$QUEUE_NAME/messages/$MESSAGE_ID?popreceipt=$POP_RECEIPT"
STRING_TO_SIGN="DELETEnnnnnnnnnnnn$HEADER_RESOURCEn$URL_RESOURCE"
DECODED_KEY="$(echo -n "$STORAGE_KEY" | base64 -d -w0 | xxd -p -c256)"
SIGN=$(printf "$STRING_TO_SIGN" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$DECODED_KEY" -binary | base64 -w0)
curl -X DELETE
-H "x-ms-date:$DATE_ISO"
-H "x-ms-version:$VERSION"
-H "Authorization: SharedKey $STORAGE_ACC:$SIGN"
"https://$STORAGE_ACC.queue.core.windows.net/$QUEUE_NAME/messages/$MESSAGE_ID?popreceipt=$POP_RECEIPT"
}
Any help would be appreciated