Hi Ahmad Firdaus
This error suggests that the Stored Access Signature token is somehow invalid and, in most cases, is due to an incorrect endpoint. Shared Access Signature token is typically invalid due to the issue related to incorrect endpoint.
The azure portal communicatins endpoint for the azure service bus namespace must be correctly provided to the generateSASToken() function. The endpoint values given to the generateSASToken() function are correct and match the given values in the Azure Portal.
The urlencode() method might not be preserving case. Check if all character cases, slashes, and special characters that need to be encoded have been appropriately taken care of.
The string used for signing the resource id must be in exact format as required by Azure Web PubSub. The resource URI for signing must have the specific format as defined by Azure Web PubSub.
Make sure that the Api version defined in the Api URL is the same version you are using when making the request. Verify that the Api version specified in the API URL is the same as the one you are using in your request.
Make sure that the primary Key being used is accurately copied from the Azure Portal as well as appropriately base64 decoded from being sent to hash_hmac. Primary key should be copied as it is shown in the Azure Portal then after base64 decoding it should be passed to hash_hmac function for processing.
https://www.php.net/manual/en/function.hash-hmac.php
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.
Let me know if you have any further Queries.