我試圖爲我的azure blob存儲創建一個SAS
,但我收到消息說我的簽名字段沒有正確形成。Azure PHP SAS blob
首先創建簽名的函數:
function getSASForBlob($accountName,$container, $blob, $resourceType, $permissions, $expiry,$key){
/* Create the signature */
$_arraysign = array();
$_arraysign[] = $permissions;
$_arraysign[] = '';
$_arraysign[] = $expiry;
$_arraysign[] = '/' . $accountName . '/' . $container . '/' . $blob;
$_arraysign[] = '';
$_arraysign[] = "2014-02-14"; //the API version is now required
$_arraysign[] = '';
$_arraysign[] = '';
$_arraysign[] = '';
$_arraysign[] = '';
$_arraysign[] = '';
$_str2sign = implode("\n", $_arraysign);
return base64_encode(
hash_hmac('sha256', urldecode(utf8_encode($_str2sign)), base64_decode($key), true)
);
}
然後提供我的URL功能:
function getBlobUrl($accountName,$container,$blob,$resourceType,$permissions,$expiry,$_signature){
/* Create the signed query part */
$_parts = array();
$_parts[] = (!empty($expiry))?'se=' . urlencode($expiry):'';
$_parts[] = 'sr=' . $resourceType;
$_parts[] = (!empty($permissions))?'sp=' . $permissions:'';
$_parts[] = 'sig=' . urlencode($_signature);
$_parts[] = 'sv=2014-02-14';
/* Create the signed blob URL */
$_url = 'https://'
.$accountName.'.blob.core.windows.net/'
. $container . '/'
. $blob . '?'
. implode('&', $_parts);
return $_url;
}
然後我打電話的功能,並指定參數。
$container = '87d57f73-a327-4344-91a4-27848d319a66';
$blob = '8C6CBCEB-F962-4939-AD9B-818C124AD3D9.mp4';
$endDate = date('YYYY-MM-DDThh:mmTZD', strtotime('+1 day'));
$_signature = getSASForBlob($accountName,$container,$blob,'b','r',$endDate,$accountKey);
$_blobUrl = getBlobUrl($accountName,$container,$blob,'b','r',$endDate,$_signature);
這是網址,我得到我的結果是,當我跟着它我得到一個錯誤信息:
AuthenticationFailed
服務器無法 驗證請求。確保授權標頭 的值正確形成,包括簽名。 請求ID:41f089a3-0001-0027-376f-6966d1000000 時間:2016-02-17T10:38:00.2724783Z簽名域不好 組成。
此修改仍然得到相同的結果 – Jeroen
我注意到的另一件事是URL中的'se'參數('2016201620162016-FebFeb-ThuThuCET1111%3A0202CET3600Thu')。您能否檢查一下您是否通過了SAS期滿的適當價值? –