This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
A shared access signature (SAS) enables you to grant limited access to containers and blobs in your storage account. When you create a SAS, you specify its constraints, including which Azure Storage resources a client is allowed to access, what permissions they have on those resources, and how long the SAS is valid.
Every SAS is signed with a key. You can sign a SAS in one of two ways:
Note
A user delegation SAS offers superior security to a SAS that is signed with the storage account key. Microsoft recommends using a user delegation SAS when possible. For more information, seeGrant limited access to data with shared access signatures (SAS).
This article shows how to use the storage account key to create a service SAS for a container or blob with the Blob Storage client library for JavaScript.
The following code example creates a SAS for a container. If the name of an existing stored access policy is provided, that policy is associated with the SAS. If no stored access policy is provided, then the code creates an ad hoc SAS on the container.
A service SAS is signed with the account access key. Use theStorageSharedKeyCredential class to create the credential that is used to sign the SAS. Next, call thegenerateBlobSASQueryParameters function providing the required parameters to get the SAS token string.
// Create a service SAS for a blob containerfunction getContainerSasUri(containerClient, sharedKeyCredential, storedPolicyName) { const sasOptions = { containerName: containerClient.containerName, permissions: ContainerSASPermissions.parse("c") }; if (storedPolicyName == null) { sasOptions.startsOn = new Date(); sasOptions.expiresOn = new Date(new Date().valueOf() + 3600 * 1000); } else { sasOptions.identifier = storedPolicyName; } const sasToken = generateBlobSASQueryParameters(sasOptions, sharedKeyCredential).toString(); console.log(`SAS token for blob container is: ${sasToken}`); return `${containerClient.url}?${sasToken}`;}The following code example creates a SAS on a blob. If the name of an existing stored access policy is provided, that policy is associated with the SAS. If no stored access policy is provided, then the code creates an ad hoc SAS on the blob.
To create a service SAS for a blob, call thegenerateBlobSASQueryParameters function providing the required parameters.
// Create a service SAS for a blobfunction getBlobSasUri(containerClient, blobName, sharedKeyCredential, storedPolicyName) { const sasOptions = { containerName: containerClient.containerName, blobName: blobName }; if (storedPolicyName == null) { sasOptions.startsOn = new Date(); sasOptions.expiresOn = new Date(new Date().valueOf() + 3600 * 1000); sasOptions.permissions = BlobSASPermissions.parse("r"); } else { sasOptions.identifier = storedPolicyName; } const sasToken = generateBlobSASQueryParameters(sasOptions, sharedKeyCredential).toString(); console.log(`SAS token for blob is: ${sasToken}`); return `${containerClient.getBlockBlobClient(blobName).url}?${sasToken}`;}The links below provide useful resources for developers using the Azure Storage client library for JavaScript
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?