0
votes

I am generating SAS (shared access signature) token for my Azure blob containers with private access level using .net core application and it is working fine.

Code:

private static string GetContainerSasUri(CloudBlobContainer container, string storedPolicyName = null)
{
  string sasContainerToken;

  if (storedPolicyName == null)
  {          
     SharedAccessBlobPolicy adHocPolicy = new SharedAccessBlobPolicy()
     {
         SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-1),
         SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(2),
         Permissions = SharedAccessBlobPermissions.Read
     };

     sasContainerToken = container.GetSharedAccessSignature(adHocPolicy, null);
   }
   else
      sasContainerToken = container.GetSharedAccessSignature(null, storedPolicyName);


    return container.Uri + sasContainerToken;
}

Now I want to do the same using Angular (generating SAS tokens). I've googled it and found some links but none of them explain this in detail. Is there anyway to do this?

1

1 Answers

2
votes

Now I want to do the same using Angular (generating SAS tokens). I've googled it and found some links but none of them explain this in detail. Is there anyway to do this?

Simple answer is no, you can't create SAS tokens from a client-side library like Angular. Well, technically you can but creation of SAS tokens require storage account key and creating it from the client side would mean that you would be exposing your storage account key to everyone who's using your application.

Better option would be to make an API call to your back-end service and have that service create a SAS token for you. That way you can keep your account key safe.