I’m experiencing an intermittent issue with SAS tokens for Azure Blob Storage. Occasionally, when attempting to access a blob using the generated SAS token, I receive a 403 error: “Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.”
Blob URL Format:https://${AzureStoreAccount}/${containerName.value}/${fileName}?${sas.value}
Code for Generating SAS Token:
import { StorageSharedKeyCredential, generateBlobSASQueryParameters, ContainerSASPermissions, SASProtocol } from '@azure/storage-blob';
// Initialize StorageSharedKeyCredential
const sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);
// Configure ContainerSASPermissions
const permissions = new ContainerSASPermissions();
permissions.read = true;
permissions.list = true;
const startDate = new Date();
startDate.setMinutes(startDate.getMinutes() - 5);
const expiryDate = new Date();
expiryDate.setHours(startDate.getHours() + 4);
// Generate SAS Token
const sasToken = generateBlobSASQueryParameters(
{
containerName: containerName,
permissions: permissions, // Use the permissions instance directly
startsOn: startDate,
expiresOn: expiryDate,
protocol: SASProtocol.Https,
version: "2020-02-10"
},
sharedKeyCredential
).toString();
Issue Description:
The SAS token is generated every time the component mounts.
Occasionally, the SAS token results in a 403 error when accessing the blob.
Any guidance on why this might be happening and how to resolve it would be greatly appreciated.