gpt4 book ai didi

node.js - 文档数据库 : Coldfusion Returning 401 Authorization error

转载 作者:太空宇宙 更新时间:2023-11-03 21:52:55 25 4
gpt4 key购买 nike

我尝试通过 Coldfusion 连接 Azure DocumentDB/CosmosDB,但收到 401 授权错误。我已经安装了证书,但仍然遇到同样的问题。我尝试过 PHP、Nodejs,除了 ColdFusion 之外,两者都表现良好。还尝试使用 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":"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\ndbs\n\nthu, 08 feb 2018 19:52:03 gmt\n\n'\r\nActivityId: aab94428-63a0-4eb7-807b-SOMETHING, Microsoft.Azure.Documents.Common/1.20.186.1"}

这段代码有什么问题?提前致谢

最佳答案

如果您将代码更改为如下所示,这将起作用:

<cfset x_ms_date = GetHttpTimeString(now()) />

<cfset strBase64ValueKey = "BASE64_ENCODED_MASTER_KEY" />
<cfset br = chr(10)>
<cfset signStr = "GET#br#dbs#br##br##x_ms_date##br##br#" />

<cfset secret = createObject('java', 'javax.crypto.spec.SecretKeySpec' ).Init(BinaryDecode(strBase64ValueKey, "Base64"), 'HmacSHA256')/>
<cfset mac = createObject('java', "javax.crypto.Mac")/>
<cfset mac = mac.getInstance("HmacSHA256")/>
<cfset mac.init(secret)/>
<cfset x = mac.doFinal(LCase(signStr).GetBytes())>
<cfset sig = BinaryEncode(x, "Base64")>
<cfset token = URLEncodedFormat("type=master&ver=1.0&sig=#sig#")>


<cfhttp method="GET" url="https://APP_URL.documents.azure.com/dbs" throwonerror="Yes">
<cfhttpparam name="Authorization" type="header" value="#token#">
<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>

关于node.js - 文档数据库 : Coldfusion Returning 401 Authorization error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48693967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com