1
votes

I have a MVC application where a list of users can upload files to GoogleDrive/DropBox and for this they just need to authenticate themselves and the corresponding api provides an 'AccessToken' or something which is further used to upload files to user account from my web application.

Now I need to do same thing with Azure Blob Storage. For testing I created an account there and using Accountname and Accountkey created a connection string which do the same like this:

public void UploadFileToBlob1(string fileName, byte[] fileData)
    {
        // Retrieve storage account from connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]);

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.GetContainerReference("portalcontainer");
        container.CreateIfNotExists();

        // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);

        // Create or overwrite the "myblob" blob with contents from a local file.
        Stream stream = new MemoryStream(fileData);
        blockBlob.UploadFromStream(stream);
    }

Now I want to make user who logged into my app, can do same.

So in case of Azure blob storage what can I do to authenticate the logged in user on Blob storage account and get an 'accesstoken' or something to perform file upload/download on the user blob container.

Please advice

1
Have you investigated whether Shared Access Signatures meets your requirements? azure.microsoft.com/en-us/documentation/articles/…Zhaoxing Lu
yes, but Shared Access Signatures required account key as well.Anil D

1 Answers

2
votes

User specific token-based access to Azure Storage is not currently supported.

However there's an alternate approach that I want to propose. See if this makes sense (this is essentially extending Zhaoxing's comment above).

For each user of your application, what you do is create a blob container (kind of home directory). When the user logs in, you can create a Shared Access Signature (SAS) for that container with appropriate permissions. A user thus will be able to access resources in that container. Because SAS is created for a specific container, any attempt by the user to access another container using that SAS token will result in an error.