简体   繁体   中英

Generate SAS token from JavaScript code?

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.

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://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-a-Service-SAS?redirectedfrom=MSDN

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM