Пример #1
0
        public static async Task <string> GetContainerSasTokenAsync(string storageAccountName, string containerName, string access_token)
        {
            TokenCredential    tokenCredential    = new Microsoft.Azure.Storage.Auth.TokenCredential(access_token);
            StorageCredentials storageCredentials = new StorageCredentials(tokenCredential);
            CloudBlobClient    client             = new CloudBlobClient(new Uri($"https://{storageAccountName}.blob.core.windows.net"), storageCredentials);
            CloudBlobContainer container          = client.GetContainerReference(containerName);

            var delegationKey = await client.GetUserDelegationKeyAsync(DateTimeOffset.UtcNow.AddMinutes(-1), DateTimeOffset.UtcNow.AddMinutes(15));

            var sas = container.GetUserDelegationSharedAccessSignature(delegationKey, new SharedAccessBlobPolicy()
            {
                SharedAccessStartTime  = DateTime.UtcNow.AddHours(-1),
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(16),
                Permissions            = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List
            });

            return(sas);
        }