【发布时间】:2018-02-08 20:10:48
【问题描述】:
我正在尝试通过冷融合连接 Azure DocumentDB/CosmosDB,但收到 401 授权错误。我已经安装了证书,但仍然有同样的问题。我尝试使用 PHP、Nodejs,除了 ColdFusion 之外,它们都表现良好。也尝试使用冷融合脚本,但错误仍然相同。这是我写的代码:
<cfset x_ms_date="#GetHttpTimeString(now())#"/>
<cfset br = "#chr(13)##chr(10)#">
<cfset signStr="GET#br#dbs#br##br##x_ms_date##br##br#" />
<cfset strBase64ValueKey="BASE64_ENCODED_MASTER_KEY" />
<cfset key=ToString(ToBinary(strBase64ValueKey))/>
<cfset x=ToBase64(hmac(LCase(signStr),LCase(key),"HMACSHA256"))>
<cfhttp method="GET" url="https://APP_URL.documents.azure.com/dbs" throwonerror="Yes">
<cfhttpparam name="Authorization" type="header" value="#URLEncodedFormat("type=master&ver=1.0&sig="&x)#">
<cfhttpparam name="x-ms-date" type="header" value="#x_ms_date#">
<cfhttpparam name="x-ms-version" type="header" value="2017-02-22">
</cfhttp>
<cfoutput>
#cfhttp.fileContent#
</cfoutput>
这是上面代码的响应:
{"code":"Unauthorized","message":"输入的授权令牌不能 服务请求。请检查预期的有效载荷是否构建为 根据协议,并检查正在使用的密钥。服务器使用了 以下要签名的有效负载:'get\ndbs\n\nthu, 2018 年 2 月 8 日 19:52:03 gmt\n\n'\r\nActivityId: aab94428-63a0-4eb7-807b-SOMETHING, Microsoft.Azure.Documents.Common/1.20.186.1"}
该代码有什么问题?提前致谢
【问题讨论】:
标签: node.js azure coldfusion azure-cosmosdb