Hello Collin Yarrington,
Thank you for posting your query here!
Can you please check with the code below and let us know if it helps to generate SAS token restricted to the specified container, providing container-level access with the specified permissions and time constraints.
$accountName = config('azure.blob_storage.account_name');
$accountKey = config('azure.blob_storage.access_key');
$signedPermissions = "rw";
$signedStart = now()->utc()->format('Y-m-d\TH:i:s\Z');
$signedExpiry = now()->utc()->addHour()->format('Y-m-d\TH:i:s\Z');
$protocol = "https";
$signedVersion = "2017-04-17";
$signedProtocol = "https";
$signedResource = "c";
$containerName = "your-container-name"; // Replace with your actual container name
$stringToSign = $accountName . "\n";
$stringToSign .= $signedPermissions . "\n";
$stringToSign .= "b" . "\n";
$stringToSign .= $signedResource . "\n";
$stringToSign .= $containerName . "\n";
$stringToSign .= "\n";
$stringToSign .= $signedStart . "\n";
$stringToSign .= $signedExpiry . "\n";
$stringToSign .= "\n";
$stringToSign .= $signedProtocol . "\n";
$stringToSign .= $signedVersion . "\n";
// Signing the $stringToSign
$signature = base64_encode(hash_hmac('sha256', $stringToSign, base64_decode($accountKey), true));
// Encoding signature
$urlEncodedSignature = rawurlencode($signature);
// Constructing the SAS token
$sasToken = "?sv=" . $signedVersion .
"&ss=b&srt=" . $signedResource .
"&sp=" . $signedPermissions .
"&st=" . $signedStart .
"&se=" . $signedExpiry .
"&spr=" . $protocol .
"&sig=" . $urlEncodedSignature;
dd($sasToken);
Similar posts that might help:
https://stackoverflow.com/questions/77751969/generating-sas-token-for-azure-blob-storage-in-php-with-rest-api
Please let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.