【问题标题】:Is there a way to regenerate Azure Blob Storage SAS token有没有办法重新生成 Azure Blob 存储 SAS 令牌
【发布时间】:2021-11-08 19:34:49
【问题描述】:

我使用 azure-sdk-for-js (NodeJS)。 特别是 - @azure/storage-blob@12.6.0。

我有一个生成 SAS 令牌的服务,它们会在几分钟后过期。我想在上次过期后以某种方式请求新令牌。即使在操作过程中也应该这样做。因为当我将大文件上传到 blob 时,中间 SAS 令牌过期并且上传失败。

我有一个我需要的工作示例,但使用 EventHub。 我创建事件中心客户端:

new EventHubProducerClient(eventHubHost, eventHubName, sasGenerator)

而sasGenerator 是TokenCredential 的实现。它返回生成的AccessToken(具有 SAS 令牌和 expiresOnTimestamp)。如果我理解正确,EventHubProducerClient 在需要时使用我的sasGenerator 刷新令牌。

我发现BlobServiceClient 有类似的参数credential 可以有TokenCredential 的类型。但是与 EventHub 相同的方法不起作用:

new BlobServiceClient(blobHost, sasGenerator)

错误示例:

RestError: Server failed to authenticate the request. Please refer to the information in the www-authenticate header

我还能够将生成的 SAS 令牌与AnonymousCredential 一起使用,并且可以正常工作。但我无法将大文件上传到 blob,因为令牌提前过期。

【问题讨论】:

    标签: node.js azure azure-blob-storage


    【解决方案1】:

    请检查以下几点,如果它们可以解决

    1. 错误Server failed to authenticate the request. Please refer to the information in the www-authenticate header 可能是由于存储在配置文件或连接字符串中的帐户名/密钥存在问题。 这可能是由于权限顺序不正确。请参阅Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. 和valid permission order。

    2. 遇到了这个 Article 关于如何为持续上传注入新 SAS 的信息。 该方案提供了在上传期间请求新 SAS 令牌而不是开始新上传的示例。

    见:

    1. work-with-shared-access-signatures
    2. Best practices using sas

    【讨论】:

    • 请停止发布文章链接,您的答案中没有实际内容。在您的答案中发布任何相关代码、解释等,并且仅包含链接作为附加资源。
    • 文章在上传期间自定义 HTTP 管道和策略以动态注入 SAS 中描述的方法应该可以工作,尽管它是为旧版本的 azure blob 存储库编写的,所以你目前需要移植它。我在github.com/Azure/azure-sdk-for-js/issues/17836 记录了一个文档和示例改进问题
    猜你喜欢
    • 2020-05-30
    • 2018-08-14
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 2020-03-29
    • 2018-12-12
    • 2021-10-02
    • 2020-03-08
    相关资源
    最近更新 更多