3

There is the requirement to generate SAS token from the client side JavaScript, I have visited many blogs there isn't any live code example of JavaScript code for generating SAS token. I want a working code for generating SAS token from JavaScript.

2 Answers 2

3

Found this on web

There's a reason for using a server-side backend to generate the token. In order to generate a token, you would need account key. You could very well generate a SAS token using client-side JavaScript but in order to do that, you would need to expose the account key to your client application which is a big security risk because if someone has key to your account, they can do anything with your storage account. Thus it is recommended that you create SAS token using a server-side application so that you don't expose your account key.

If you still wish to create a SAS token using Client-Side JavaScript, please see Constructing a Service SAS. Essentially go to the section titled Constructing the Signature String at the bottom of that link and write code in JavaScript for that, and compute signature using account key.

https://learn.microsoft.com/en-us/rest/api/storageservices/Constructing-a-Service-SAS?redirectedfrom=MSDN

2
  • The code on that link is not for JavaScript I have already checked that.
    – Ahmer Khan
    Commented Oct 17, 2017 at 6:34
  • Completely agree with the answer. +1. The link mentioned in the answer has all the instructions you would need to write code in JavaScript. If you need to look at the actual implementation closer to client side JS, may I suggest you take a look at Node SDK for Azure Storage: github.com/Azure/azure-storage-node. Commented Oct 17, 2017 at 6:48
1

The Azure storage team has published Azure Storage JavaScript Client Library for Browsers to address your use case. There was an official announcement explaining the rationale behind it several months ago. This library is still in Preview, I could not find any distinct nuget or bower packages.

As was already noted by others, please follow recommended development practices, mentioned in the announcement as well, when using SAS within your application. Luckily using Shared Access Signatures (SAS) is well documented these days - as well as more general guide to Azure Storage security.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.