【问题标题】:Decode Azure Blob SAS Url correctly to avoid Signature not well formed error正确解码 Azure Blob SAS Url 以避免签名格式错误
【发布时间】:2022-06-13 18:01:40
【问题描述】:

为了在 Neo4j 中进一步处理,我需要未转义的 SAS 编码 URL,因为 Neo4j 再次进行编码并导致 403 http 错误代码。

将 json 文件上传到 Azure Blob 存储并获取编码的 SAS Url 并使用 DecodeUrlString 对其进行解码的代码:

BlobContainerClient containerClient = new BlobContainerClient(absConnectionString, absContainerName);
await containerClient.CreateIfNotExistsAsync();

string fileName = fileKey + ".json";

// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);

await using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
    response = await blobClient.UploadAsync(ms, new BlobUploadOptions
    {
        HttpHeaders = new BlobHttpHeaders
        {
            ContentType = "application/json",
            ContentEncoding = "UTF-8"
        }
    });
}

var absoluteUrl = string.Empty;
if (response.GetRawResponse().Status == 201)
{
    // 1 hour valid
    var originalUrl = blobClient.GenerateSasUri(BlobSasPermissions.Read, DateTimeOffset.UtcNow.AddHours(1)).AbsoluteUri;
    originalUrl = DecodeUrlString(originalUrl);
}


private static string DecodeUrlString(string url)
    {
        string newUrl;
        while ((newUrl = Uri.UnescapeDataString(url)) != url)
            url = newUrl;
        
        return newUrl;
    }

有时解码后的 URL 会起作用,有时我在 Neo4j 和浏览器中遇到此错误(取决于 SAS 编码的 URL,尤其是 Signature 字段 => 以 &sig= 开头):

AuthenticationFailed 服务器失败 验证请求。确保 Authorization 标头的值 格式正确,包括签名。 请求ID:552242c2-301e-003e-55d9-457612000000 时间:2022-04-01T15:04:20.4824344Z 签名字段不好 形成。

原始 Blob 网址:

https://[ACCOUNTNAME].blob.core.windows.net/[CONTAINER]/file.json?sv=2021-04-10&se=2022-04-01T10%3A10%3A46Z&sr=b&sp=r&sig=%2BTCB%2FwyaV5RfI7X7%2Fb7yoOlGZSzd5OjgXw2GDOCkB04%3D

解码后的网址:

https://[ACCOUNTNAME].blob.core.windows.net/[CONTAINER]/file.json?sv=2021-04-10&se=2022-04-01T10:10:46Z&sr=b&sp=r&sig=+TCB/wyaV5RfI7X7/b7yoOlGZSzd5OjgXw2GDOCkB04=

这里描述了 Neo4j 的问题:apoc.load.jsonParams with Azure Blob signed URL leads to http 403 error

如何正确取消转义 SAS URL 以避免此类错误?

【问题讨论】:

  • 你能分享一个给出错误的 SAS URL 吗?
  • 另外请说明 neo4j 在做什么以及如何存储 URI。目前还不清楚 neo4j 如何更改您的文本。
  • @GauravMantri 现已添加。
  • @DavidMakogon 我添加了指向 Neo4j 问题的链接。

标签: c# azure neo4j azure-blob-storage


【解决方案1】:

现在 Neo4j v4.4.7 和 apoc v4.4.0.5 版本已解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-09
    • 2020-06-21
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 2020-03-29
    相关资源
    最近更新 更多