【问题标题】:DocumentDB web API access with R使用 R 访问 DocumentDB Web API
【发布时间】:2017-04-07 17:44:02
【问题描述】:

我在尝试使用 R 和 PostMan 连接到 documentDB Web API 时遇到以下问题。

在 DocumentDB 文档中,向 Web API 询问某些内容的方法是使用 base64 哈希组成一个 Authorization 标头。

在 R 中,我正在尝试计算签名并直接使用邮递员测试标头。 但我每次都得到一个http 401。 这是我的 R 代码:

toHash <- enc2utf8("get\ncolls\ndbs/toto/colls/testtoto\nsun, 08 may 2016 06:43:05 gmt\n\n")
hash <- hmac(key, toHash, "sha256")
base64(hash)

“key”是从门户获得的主键。 然后,按照 Azure 文档,我的标题是:

type=master&ver=1.0&sig=< thebase64(hash) >

我将其粘贴到 PostMan 中,标题为 x-ms-version、date 和 x-ms-date。

但它不起作用..

我现在卡住了,有人知道吗?我使用了错误的 R 函数吗?一个错误的密钥,有没有办法获得有关不匹配的更多信息?

web api 响应是:

{
  "code": "Unauthorized",
  "message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get\ncolls\ndbs/toto/colls/testtoto\nsun, 08 may 2016 06:43:05 gmt\n\n'\r\nActivityId: fadbfc0b-e298-418a-b56c-8114699fff91"
}

【问题讨论】:

    标签: r azure-cosmosdb


    【解决方案1】:

    我自己发现了问题所在。

    Azure 门户中给出的令牌是 base64 编码的。所以必须解码:

    RCurl::base64Decode(key, mode="raw")
    

    为了将它与digest::hmac 函数一起使用。在此hmac 函数中还必须指定raw = TRUE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 2015-08-24
      • 2017-02-13
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多