locked
Azure Storage Emulator - Shared Access Signatures? RRS feed

  • Question

  • Hi,
    I would like to test Shared Access Signatures with the Azure Storage Emulator.

    So question are:

    1. Is it possible? Any limitations with it?
    2. How would I change the code below to make it work. The problem is working out the URI's.

    Thanks,
    Ward.

            public void fnOpen_Table(string storage_account_name,
                                     string shared_access_signature,
                                     string table_name)
            {
                try
                {
                    StorageCredentials creds = new StorageCredentials(shared_access_signature);
                    string endpoint = string.Format("https://{0}.table.core.windows.net", storage_account_name);
                    CloudTableClient table_client = new CloudTableClient(new Uri(endpoint), creds);
                    CloudTale cloud_table = table_client.GetTableReference(table_name);
                }
                catch (Exception ex)
                {
                    throw (ex);
                }
            }


    • Edited by WardH Sunday, June 7, 2015 8:22 AM
    Sunday, June 7, 2015 8:21 AM

Answers

  • Hi WardH -

    I didn't realize that you were using the Xamarin library. I investigated your issue further and you are right, you need to use a SAS to access the emulator or your storage account from Xamarin. 

    Also, SAS is now supported for the emulator, so we'll update the docs to correct that.

    Hopefully this will help you with your problem:

    It looks like you’re trying to use SharedKey access for the emulator (CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azure_connection);). You’ll need to generate a SAS token outside of the Xamarin app to access storage resources via Xamarin. Please see our tutorial here: http://blogs.msdn.com/b/windowsazurestorage/archive/2015/04/29/getting-started-with-azure-storage-on-xamarin.aspx for more information on getting started with Xamarin & Storage. Of particular importance is the section entitled “Generate a Shared Access Signature” which shows a simple Powershell method for creating a SAS token for a production account. This method also can be edited to have the token target the storage emulator.

    You may also need special configuration for your Android Emulator or Android Device to get it to access the Storage Emulator, depending on your environment.
    Monday, June 8, 2015 10:31 PM

All replies

  • Hi WardH,

    Thank you for reaching out to us.

    Will have someone from the respective team to address your query.

    Sincerely appreciate your patience.

    Regards,

    Sadiqh

    Sunday, June 7, 2015 4:13 PM
  • Hi WardH -

    I didn't realize that you were using the Xamarin library. I investigated your issue further and you are right, you need to use a SAS to access the emulator or your storage account from Xamarin. 

    Also, SAS is now supported for the emulator, so we'll update the docs to correct that.

    Hopefully this will help you with your problem:

    It looks like you’re trying to use SharedKey access for the emulator (CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azure_connection);). You’ll need to generate a SAS token outside of the Xamarin app to access storage resources via Xamarin. Please see our tutorial here: http://blogs.msdn.com/b/windowsazurestorage/archive/2015/04/29/getting-started-with-azure-storage-on-xamarin.aspx for more information on getting started with Xamarin & Storage. Of particular importance is the section entitled “Generate a Shared Access Signature” which shows a simple Powershell method for creating a SAS token for a production account. This method also can be edited to have the token target the storage emulator.

    You may also need special configuration for your Android Emulator or Android Device to get it to access the Storage Emulator, depending on your environment.
    Monday, June 8, 2015 10:31 PM
  • Hi Tamra,

    Thanks for getting back to me the issue I am having is using the storage emulator via a Xarmin Andriod native app.

    Here is the code module below so you can see what I am doing. I would like to be able to use the storage emulator for testing.

    Since when I try to access via a normal storage account key method I get the exception:

    Shared Key is not supported using the PCL. Please use a SAS token

    So from this I assume I should be using a SAS token.

    I am assuming this is the way to go. Then if I try to use some code to access the storage emulator I get the error message:

    No valid combination of account information found."

    The question is how to from this type of App do I access the Azure Storage emulator.

    I have included my code below.

    Thanks,

    Ward.

    using System;
    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;

    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Table;
    using Microsoft.WindowsAzure.Storage.Auth;

    using System.Threading.Tasks;
    using System.Collections.Generic;

    namespace Andriod_Storage_Emulator_Test
    {
        [Activity(Label = "Andriod_Storage_Emulator_Test", MainLauncher = true, Icon = "@drawable/icon")]
        public class MainActivity : Activity
        {
            int count = 1;

            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);

                // Get our button from the layout resource,
                // and attach an event to it
                Button button = FindViewById<Button>(Resource.Id.MyButton);

                button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };

                string storage_account_name = "";
                string storage_account_key = "";
                string table_name;

                storage_account_name = "....";
                storage_account_key =  "....";

                table_name = "customer";

                string exception_message = null;


                // Attempt using normal storage account
                //
                //      "Shared Key is not supported using the PCL. Please use a SAS token."

                try
                {
                    string azure_connection = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                                                 storage_account_name,
                                                 storage_account_key);

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azure_connection);
                    CloudTableClient table_client = storageAccount.CreateCloudTableClient();
                    CloudTable cloud_table = table_client.GetTableReference(table_name);
                }
                catch (Exception ex)
                {
                    exception_message = ex.Message;
                }

                // Attempt using Storage emulator..
                //
                // "No valid combination of account information found."
                //
                try
                {
                    string azure_connection = "UseDevelopmentStorage=true";

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azure_connection);
                    CloudTableClient table_client = storageAccount.CreateCloudTableClient();
                    CloudTable cloud_table = table_client.GetTableReference(table_name);
                }
                catch (Exception ex)
                {
                    exception_message = ex.Message;
                }


            }

        }
    }


    • Edited by WardH Tuesday, June 9, 2015 3:20 AM
    Tuesday, June 9, 2015 2:48 AM
  • Hi Tamra, Perry, Sadiqh,

    Thanks for your help on this one it was great :)

    Ward.

    Tuesday, June 16, 2015 11:01 AM
  • Hi - I'm trying to get the Sas Token workflow working with a local storage emulator, but not getting it right.

    Running into auth issues.

    Github repo: InquisitorJax -> Xamarin-Forms-Azure-Blob-Storage

    Run the server project, and then execute the UWP example.

    a secondary question would be how to get the Android Emulator example working.

    Any help really appreciated.

    Saturday, October 21, 2017 10:39 AM
  • @Malcolm Jack

    Take a look at Authenticating requests against the storage emulator. It should help you get going.

    -----------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    • Proposed as answer by Md Shihab Wednesday, October 25, 2017 4:16 AM
    Tuesday, October 24, 2017 8:29 AM