コード例 #1
0
        public async Task SasAuth()
        {
            string storageUri  = StorageUri;
            string accountName = StorageAccountName;
            string accountKey  = PrimaryStorageAccountKey;
            string tableName   = "OfficeSupplies";

            #region Snippet:TablesAuthSas
            // Construct a new <see cref="TableServiceClient" /> using a <see cref="TableSharedKeyCredential" />.

            var credential = new TableSharedKeyCredential(accountName, accountKey);

            var serviceClient = new TableServiceClient(
                new Uri(storageUri),
                credential);

            // Build a shared access signature with the Write and Delete permissions and access to all service resource types.

            TableAccountSasBuilder sasWriteDelete = serviceClient.GetSasBuilder(TableAccountSasPermissions.Write | TableAccountSasPermissions.Delete, TableAccountSasResourceTypes.All, new DateTime(2040, 1, 1, 1, 1, 0, DateTimeKind.Utc));
            string tokenWriteDelete = sasWriteDelete.Sign(credential);

            // Create the TableServiceClients using the SAS URIs.

            var serviceClientWithSas = new TableServiceClient(new Uri(storageUri), new AzureSasCredential(tokenWriteDelete));

            // Validate that we are able to create a table using the SAS URI with Write and Delete permissions.

            await serviceClientWithSas.CreateTableIfNotExistsAsync(tableName);

            // Validate that we are able to delete a table using the SAS URI with Write and Delete permissions.

            await serviceClientWithSas.DeleteTableAsync(tableName);

            #endregion
        }