使用R进行DocumentDB Web API访问 [英] DocumentDB web API access with R

查看:66
本文介绍了使用R进行DocumentDB Web API访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用R和PostMan连接到documentDB Web API时,出现以下问题.

I have the following issue when trying to connect to the documentDB web API with R and PostMan.

在DocumentDB文档中,向Web API提出问题的方法是使用base64哈希组成一个Authorization标头.

In the DocumentDB documentation the way to ask something to the web API is to compose an Authorization header with base64 hash.

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

In R I'm trying to compute the signature and test the header directly with postman. But I get every time a http 401. Here is my R code:

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)

键"是从门户网站获得的主键. 然后,按照Azure文档,我的标题是:

the "key" is the primary key got from the portal. And then, following the Azure documentation, my header is:

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

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

I'm pasting that into PostMan with the headers x-ms-version, date and x-ms-date.

但是它不起作用.

我现在被困住了,有人知道吗?我使用了错误的R函数吗?密钥错误,是否有办法获取有关不匹配的更多信息?

I'm stuck now, does anyone have an idea? Am I using a wrong R function? A wrong key, is there a way to get more information about the mismatch?

网络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"
}

推荐答案

我发现自己出了什么问题.

I found what was wrong by myself.

Azure门户中给定的令牌是base64编码的.因此,必须对其进行解码:

The token given in the Azure portal is base64 encoded. So It is mandatory to decode it:

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

以便与digest::hmac函数一起使用.在此hmac函数中也必须指定raw = TRUE.

in order to use it with the digest::hmac function. It is also mandatory to specify raw = TRUE within this hmac function.

这篇关于使用R进行DocumentDB Web API访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆