public async Task SharedKeyAuthAsync() { // Get a Storage account name, shared key, and endpoint Uri. // // You can obtain both from the Azure Portal by clicking Access // Keys under Settings in the Portal Storage account blade. // // You can also get access to your account keys from the Azure CLI // with: // // az storage account keys list --account-name <account_name> --resource-group <resource_group> // string accountName = StorageAccountName; string accountKey = StorageAccountKey; Uri serviceUri = StorageAccountFileUri; // Create a SharedKeyCredential that we can use to authenticate StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey); // Create a client that can authenticate with a connection string FileServiceClient service = new FileServiceClient(serviceUri, credential); // Make a service request to verify we've succesfully authenticated await service.GetPropertiesAsync(); }
public async Task SharedAccessSignatureAuthAsync() { // Create a service level SAS that only allows reading from service // level APIs AccountSasBuilder sas = new AccountSasBuilder { // Allow access to files Services = new AccountSasServices() { Files = true }.ToString(), // Allow access to the service level APIs ResourceTypes = new AccountSasResourceTypes() { Service = true }.ToString(), // Allow read access Permissions = new AccountSasPermissions() { Read = true }.ToString(), // Access expires in 1 hour! ExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }; // Create a SharedKeyCredential that we can use to sign the SAS token StorageSharedKeyCredential credential = new StorageSharedKeyCredential(StorageAccountName, StorageAccountKey); // Build a SAS URI UriBuilder sasUri = new UriBuilder(StorageAccountFileUri); sasUri.Query = sas.ToSasQueryParameters(credential).ToString(); // Create a client that can authenticate with the SAS URI FileServiceClient service = new FileServiceClient(sasUri.Uri); // Make a service request to verify we've succesfully authenticated await service.GetPropertiesAsync(); // Try to create a new container (which is beyond our // delegated permission) StorageRequestFailedException ex = Assert.ThrowsAsync <StorageRequestFailedException>( async() => await service.CreateShareAsync(Randomize("sample-share"))); Assert.AreEqual(403, ex.Status); }
public async Task ConnectionStringAsync() { // Get a connection string to our Azure Storage account. You can // obtain your connection string from the Azure Portal (click // Access Keys under Settings in the Portal Storage account blade) // or using the Azure CLI with: // // az storage account show-connection-string --name <account_name> --resource-group <resource_group> // // And you can provide the connection string to your application // using an environment variable. string connectionString = ConnectionString; // Create a client that can authenticate with a connection string FileServiceClient service = new FileServiceClient(connectionString); // Make a service request to verify we've succesfully authenticated await service.GetPropertiesAsync(); }