Код: Выделить всё
function generateSasToken($accountName, $accountKey, $blobName, $containerName, $expiryTime = '+1 hour') {
// Get current UTC time and expiry time (in ISO 8601 format)
$start = gmdate('Y-m-d\TH:i:s\Z'); // Current time in UTC format
$expiry = gmdate('Y-m-d\TH:i:s\Z', strtotime($expiryTime)); // Expiry time in UTC format
// Construct the URL for the blob (to be used in SAS token)
$url = "https://$accountName.blob.core.windows.net/$containerName/$blobName";
// Set SAS parameters
$permissions = 'r'; // Read permissions
$services = 'b'; // Blob service
$resource = 'c'; // Container resource
$protocol = 'https'; // Protocol (HTTPS only)
$version = '2022-11-02'; // API version
// Build the string to sign (format: [permissions] \n [services] \n [resource] \n [start] \n [expiry] \n [protocol] \n [version])
$stringToSign = "$permissions\n$services\n$containerName\n$start\n$expiry\n$protocol\n$version";
// Decode the account key from base64 (used for HMAC calculation)
$decodedAccountKey = base64_decode($accountKey);
// Generate the signature using HMAC-SHA256
$signature = base64_encode(hash_hmac('sha256', $stringToSign, $decodedAccountKey, true));
// Build the full SAS token with all required parameters
$sasToken = "sv=$version&ss=$services&srt=$resource&sp=$permissions&se=$expiry&st=$start&spr=$protocol&sig=" . urlencode($signature);
// Return the full SAS URL
return "$url?$sasToken";
}
AuthenticationFailed
Серверу не удалось аутентифицировать запрос. Убедитесь, что значение заголовка авторизации сформировано правильно, включая подпись. ...
Подпись не совпадает. Используемая строка для подписи была ...
Подробнее здесь: https://stackoverflow.com/questions/791 ... -header-is
Мобильная версия