我尝试使用azure节点SDK生成共享访问签名,但返回的令牌无效/缺少某些参数。
我用:
创建令牌app.get('/node-api/get-azure-token', (req, res, next) => {
var blobService = azure.createBlobService(myStorageAccount, myAccessKey);
var container = 'my-azure-container-name';
var startDate = new Date();
var expiryDate = new Date(startDate);
expiryDate.setMinutes(startDate.getMinutes() + 10);
startDate.setMinutes(startDate.getMinutes() - 5);
var sharedAccessPolicy = {
AccessPolicy: {
ServiceVersion: '2016-05-31',
Permissions: azure.BlobUtilities.SharedAccessPermissions.READ + azure.BlobUtilities.SharedAccessPermissions.WRITE + azure.BlobUtilities.SharedAccessPermissions.DELETE + azure.BlobUtilities.SharedAccessPermissions.LIST + azure.BlobUtilities.SharedAccessPermissions.ADD + azure.BlobUtilities.SharedAccessPermissions.CREATE,
Start: startDate,
Expiry: expiryDate,
Protocols: 'https,http'
}
};
const key = blobService.generateSharedAccessSignature(container, req.query.bloburi, sharedAccessPolicy);
res.send(key);
});
错误'服务器无法验证请求。确保正确形成Authorization标头的值,包括签名。'使用生成的sas令牌时抛出。
有没有人遇到过这个问题?
答案 0 :(得分:2)
我刚想通了! AccessPolicy对象中的权限顺序必须符合此处显示的顺序:https://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-a-Service-SAS?redirectedfrom=MSDN