QuentinCG / QAzureStorageRestApi

[Done] Standalone Azure Storage REST API client for Qt5+ & Qt6+ (Tested with Qt 5.12.12 & Qt 6.2.3)
MIT License
2 stars 4 forks source link

Get a Shared Access Signature (SAS) for a file #11

Closed fverneau closed 10 months ago

fverneau commented 10 months ago

I would need to obtain a URL with a Shared Access Signature (SAS) for a file present in a Blob Container like for example: https://MyStorageAccount.blob.core.windows.net/MyContainer/test.txt?sv=2021-10-04&st=2023-11-08T08%3A13%3A14Z&se=2023-11-09T08%3A13%3A14Z&sr=b&sp=r&sig=XSypll1f0Iha5AwJP2P7rS8AeYS9Qc0aCkzR7%2BFtrYU%3D Is it possible ?

QuentinCG commented 10 months ago

This project only supports account credentials and can't generate a SAS token.

I think the SAS token can be generated from Azure webiste, and then you just have to call:

QString sasCredential = "sv=2021-10-04&st=2023-11-08T08(...)CkzR7%2BFtrYU"; azure.generateUrl(container, azureFilenameToDownload, sasCredential)

QuentinCG commented 10 months ago

Is this still an issue or the example is working for you ?

fverneau commented 10 months ago

It's OK, but now I will have to find a solution to retrieve a SAS Token via Microsoft's REST APIs. Thanks again.

QuentinCG commented 10 months ago

If you are ok everyone can access the blob in read access, you can:

Else, if you need to have specific token for each file, you'll need Microsoft API :(

fverneau commented 10 months ago

I created a SAS token at the container level and used it directly in the URL of the files. It works very well. Many thanks again!

QuentinCG commented 10 months ago

Perfect !

It would be perfect if you can provide the procedure to get this token so I add it in the readme for other people using the lib ? (url of azure page & Screenshot of the azure token creation without "private" information of course)

fverneau commented 10 months ago

To obtain a shared access signature (SAS) for a container, and therefore applicable to all the files it contains, simply use Microsoft Azure Storage Explorer (https://azure.microsoft.com/en-us/products/storage/storage-explorer/). You must create a new connection to the Azure Storage Account (image 01.png) and select a method based on an Account Name and a key (image 02.png), then enter the name of the Azure Storage account as well as its key (image 03.png), then connect to it (image 04.png). Right-click on the container name, then click on Get Shared Access Signature. You must then define the start and end date as well as the permissions (image 05.png), then create. You must then copy the value of the SAS Token. These parameters will be copied at the end of the URL of the files present in the Azure container. For example, for a "test.txt" file accessible on the MyContainer container with the MyAccount account: https://MyAccount.blob.core.windows.net/MyContainer/test.txt With the SAS Token, the URL becomes: https://MyAccount.blob.core.windows.net/MyContainer/test.txt?sv=2023-01-03&st=2023-11-09T11%3A59%3A53Z&se=2023-11-10T11%3A59%3A53Z&sr=c&sp= rl&sig=w94(...)oD What can be obtained using the function: azure.generateUrl(container, azureFilenameToDownload, sasCredential)

01 02 03 04 05

QuentinCG commented 10 months ago

Thanks a lot, I'll add this this evening :)

QuentinCG commented 10 months ago

Documentation added, thanks ;) (I credited you for this documentation)