简体   繁体   English

使用共享访问签名的Azure文件存储API访问

[英]Azure File Storage API access using Shared Access Signature

I'm currently trying to access files & directories on an Azure Storage Account Fileshare (let's call it rootdirectory ) from a Dynamics Business Central page action. 我目前正在尝试通过Dynamics Business Central页面操作访问Azure存储帐户Fileshare (称为rootdirectory )上的文件和目录。

The method to access files stored in it is to build and send an HTTP GET request (with a client) to https://myaccount.file.core.windows.net/myfileshare/rootdirectory to retrieve a filelist. 访问存储在其中的文件的方法是构建HTTP GET请求(使用客户端)并将其发送到https://myaccount.file.core.windows.net/myfileshare/root目录,以检索文件列表。

I'm trying to use a Shared Access Signature to authenticate the request. 我正在尝试使用共享访问签名来验证请求。

The blocking point that I can't get through is the following error message : 我无法通过的阻止点是以下错误消息:

Authentication information is not given in the correct format. Check the value of Authorization header.

I'm setting my request headers like this : 我正在这样设置我的请求标头:

client.DefaultRequestHeaders().Clear();
client.DefaultRequestHeaders().Add('x-msdate', '2019-02-20');
client.DefaultRequestHeaders().Add('Authorization', '...');

My main problem is that I can't seem to find the proper format (to use in the '...' part) asked in the error message in any tutorial . 我的主要问题是,我似乎找不到任何教程中错误消息要求的正确格式(在“ ...”部分中使用)。

I've tried the following formats (and minor variations inside it) 我尝试了以下格式(其中的细微变化)

'SharedAccessSignature myaccount:signature'
'SharedAccessSignature sv=2018-03-28&ss=f&srt=sco&sp=rwdlc&se=2019-02-20T18:12:27Z&st=2019-02-20T10:12:27Z&spr=https&sig=signature'
'SharedAccessSignature sr=https%3A%2F%2Fmyaccount.file.core.windows.net%2Fmyfileshare%2Frootdirectory&sig=signature&se=2019-02-21T22:36:05Z&skn=key1'

I also tried putting it in the service URI, nothing better. 我还尝试将其放在服务URI中,再好不过了。

Has anyone already encountered this issue ? 有人遇到过这个问题吗?

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks for your time. 谢谢你的时间。

I would highly recommend checking the following post . 我强烈建议您检查以下帖子 They ended up using the below code: 他们最终使用以下代码:

public AzureSASToken GetSASFromShare(string shareName)
        {
            var share = _fileclient.GetShareReference(shareName);
            share.CreateIfNotExists();
            string policyName = "UPARSharePolicy";

            // Create a new shared access policy and define its constraints.
            var sharedPolicy = new SharedAccessFilePolicy()
            {
                SharedAccessExpiryTime = DateTime.UtcNow.AddDays(15),
                Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write
            };

            // Get existing permissions for the share.
            var permissions = share.GetPermissions();

            // Add the shared access policy to the share's policies. 
            // Note that each policy must have a unique name.
            // Maximum 5 policies for each share!
            if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                if (permissions.SharedAccessPolicies.Count > 4)
                {
                    var lastAddedPolicyName = permissions.SharedAccessPolicies.Keys.Last();
                    permissions.SharedAccessPolicies.Remove(lastAddedPolicyName);
                }
                permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
                share.SetPermissions(permissions);
            }            

            var sasToken = share.GetSharedAccessSignature(sharedPolicy);
            //fileSasUri = new Uri(share.StorageUri.PrimaryUri.ToString() + sasToken);
            return new AzureSASToken ()
            {
               Name = shareName,
               Url = share.StorageUri.PrimaryUri.ToString() + "/",
               SASToken = sasToken        
            };
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Azure存储API生成Azure共享访问签名 - Generate Azure Shared Access Signature with out using Azure Storage API 使用 SAS(共享访问签名)使用 Azure 存储上传文件 - Upload file with Azure Storage using SAS (Shared Access Signature) Azure Blob 存储共享访问签名 (SAS) - 签名不匹配 - Azure Blob Storage Shared Access Signature (SAS) - Signature did not match 没有API的Azure Blob共享访问签名 - Azure Blob Shared Access Signature without the api 从控制台应用程序为Azure存储帐户访问生成共享访问签名URI>如何将结果输出到文件? - Generating Shared Access Signature URI from console application for Azure Storage Account Access > how to output results to file? 使用 php 的 Azure 共享访问签名错误 - Azure Shared Access Signature error using php 是 azure 存储共享访问签名 (SAS) 所需的授权 header - Is an authorization header required by the azure storage shared access signature (SAS) REST API 使用Powershell为Azure云存储帐户创建共享访问签名(SAS) - Create a Shared Access Signature (SAS) for an Azure Cloud Storage Account with powershell 如何验证 Azure Blob 存储共享访问签名 (SAS) URL? - How to validate Azure Blob Storage Shared Access Signature (SAS) URL? Azure blob存储:多个容器的共享访问签名? - Azure blob storage: Shared access signature for multiple containers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM