Skip to content

Instantly share code, notes, and snippets.

@1c7
Created April 22, 2020 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1c7/ae1dcab2088c51051fb6ee2f7da93eb4 to your computer and use it in GitHub Desktop.
Save 1c7/ae1dcab2088c51051fb6ee2f7da93eb4 to your computer and use it in GitHub Desktop.
Azure generateAccountSASQueryParameters example (Node.js demo) (Node v12.11.0) (package.json "@azure/storage-blob": "12.1.1")
module.exports.azure_sas = function () {
var accountName = '<storage account name>'
var accountKey = '<account key like: xxxTAujFeBxdic/6a1SgEaoeByhqQeUpRdWaQ8Y7kRJ1rhwbXEoW8WAg036B4jkzTE9AYmtKnFu03dt6g1jJyA==>'
var sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey)
var last_day_of_this_year = new Date(new Date().getFullYear(), 11, 31)
var resource_types = new AccountSASResourceTypes()
resource_types.container = true
resource_types.object = true
resource_types.service = true
var permission = new AccountSASPermissions()
permission.create = true
permission.delete = true
permission.list = true
permission.write = true
var sas_signature_val = {
expiresOn: last_day_of_this_year,
services: {
blob: true
},
permissions: permission,
resourceTypes: resource_types
}
var SASQueryParameters = generateAccountSASQueryParameters(sas_signature_val, sharedKeyCredential)
var string = SASQueryParameters.toString() // sv=2019-07-07&se=2020-12-30T16%3A00%3A00Z&sp=wdlc&sig=v6x7gATh3B2D5h1H5pyEd6Q2ZXmnxd2tjZEBsF7XuWc%3D
return string
}
@1c7
Copy link
Author

1c7 commented Apr 22, 2020

I hope this is helpful for the reader who is searching "How to use generateAccountSASQueryParameters" on Google

@1c7
Copy link
Author

1c7 commented Apr 23, 2020

seem like this still doesn't work, let me fix it...

@1c7
Copy link
Author

1c7 commented May 31, 2020

Final Solution:

I stop playing with SAS, just use the SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment