Javascript 矢量api,401 http错误代码,签名不匹配。授权签名或客户端凭据错误

Javascript 矢量api,401 http错误代码,签名不匹配。授权签名或客户端凭据错误,javascript,typescript,here-api,Javascript,Typescript,Here Api,我在试着用这个。我已收到来自的凭据。我在这里为Android或iOS SDK(Lite版)创建了一个应用程序。然后,我创建了凭据,并将此处.access.key.id用于我的密钥,将此处.access.key.secret用于我的密钥 我使用的是oauth符号(在编写此问题时每周下载14.5MM,因此我认为它应该可以正常工作)和以下代码片段: 从“oauth符号”导入{hmacsign256} 导出常量API\u URL='1〕https://account.api.here.com/oauth

我在试着用这个。我已收到来自的凭据。我在这里为Android或iOS SDK(Lite版)创建了一个应用程序。然后,我创建了凭据,并将
此处.access.key.id
用于我的密钥,将
此处.access.key.secret
用于我的密钥

我使用的是
oauth符号
(在编写此问题时每周下载14.5MM,因此我认为它应该可以正常工作)和以下代码片段:

从“oauth符号”导入{hmacsign256}
导出常量API\u URL='1〕https://account.api.here.com/oauth2/token'
导出常量非长度=2**5
导出接口令牌响应{
AccessToken:字符串
标记类型:字符串
ExpiresIn:number
}
导出常量generateNonce=(长度:数字):字符串=>{
让我们=“”
做{
s+=Math.random().toString(36).substr(2)
}而(s.长度<长度)
返回s.substr(0,长度)
}
export const fetchNewTokenFromAPI=async({key,secret}:{key:string,secret:string}):Promise=>{
const url=API\u url
常量方法='POST'
const body='grant\u type=client\u凭证'
常数auth={
oauth_消费者_密钥:密钥,
oauth_nonce:generateNonce(非长度),
oauth_签名_方法:“HMAC-SHA256”,
oauth_时间戳:字符串(Math.round(new Date().getTime()/1000)),
oauth_版本:“1.0”,
}
const sig=encodeURIComponent(hmacsign256(方法、API_URL、身份验证、密钥、机密))
常量头={
“内容类型”:“应用程序/x-www-form-urlencoded”,
“授权”:OAuth OAuth_consumer_key=“${auth['OAuth_consumer_key']}”、OAuth_nonce=“${auth['OAuth_nonce']}”、OAuth_签名=“${sig}”、OAuth_签名方法=“HMAC-SHA256”、OAuth_时间戳=“${auth['OAuth_timestamp']}”、OAuth_version=“1.0”`
}
常量选项:RequestInit={
方法,,
标题,
身体,
模式:“cors”,
}
const response=等待获取(url、选项)
if(response.ok)
抛出新错误(`expected 200 status,received${response.status}`)
return wait response.json()
}
当我运行该函数时,我从api接收到以下内容:

{
  "error": "invalid_client"
  "errorCode": 401300
  "errorId": "ERROR-32e365d0-11ce-4fff-86d7-5ca51970e017"
  "error_description": "errorCode: '401300'. Signature mismatch. Authorization signature or client credential is wrong."
  "httpStatus": 401
  "message": "Signature mismatch. Authorization signature or client credential is wrong."
}

在postman上测试令牌生成API后共享CURL请求。使用者密钥和使用者机密分别位于此处.access.key.id和key.secret。签名方式:HMAC-SHA1,版本:1.0

 curl -X POST \
  https://account.api.here.com/oauth2/token \
  -H 'Authorization: OAuth' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Postman-Token: xxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  -d grant_type=client_credentials


在postman上测试令牌生成API后共享CURL请求。使用者密钥和使用者机密分别位于此处.access.key.id和key.secret。签名方式:HMAC-SHA1,版本:1.0

 curl -X POST \
  https://account.api.here.com/oauth2/token \
  -H 'Authorization: OAuth' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Postman-Token: xxxxxxxxxxxx' \
  -H 'cache-control: no-cache' \
  -d grant_type=client_credentials

curl-X POST\ \ -H'接受:/'\ -H'接受编码:gzip,deflate'\ -H'授权:OAuth'\ -H'缓存控制:无缓存'\ -H'连接:保持活力'\ -H'内容长度:238'\ -H'内容类型:应用程序/x-www-form-urlencoded'\ -主机:account.api.here.com\ -H'邮递员代币:xxxxxxxxx'\ -H'用户代理:PostmanRuntime/7.20.1'\ -H'缓存控制:无缓存'\ -d'grant\u type=client\u credentials&oauth\u consumer\u key=xxxx&oauth\u signature\u method=HMAC-SHA256&oauth\u timestamp=1576653105&oauth\u nonce=xxx&oauth\u version=1.0&oauth\u signature=xxx'

curl-X POST\ \ -H'接受:/'\ -H'接受编码:gzip,deflate'\ -H'授权:OAuth'\ -H'缓存控制:无缓存'\ -H'连接:保持活力'\ -H'内容长度:238'\ -H'内容类型:应用程序/x-www-form-urlencoded'\ -主机:account.api.here.com\ -H'邮递员代币:xxxxxxxxx'\ -H'用户代理:PostmanRuntime/7.20.1'\ -H'缓存控制:无缓存'\
-d'grant\u type=client\u credentials&oauth\u consumer\u key=xxxx&oauth\u signature\u method=HMAC-SHA256&oauth\u timestamp=1576653105&oauth\u nonce=xxx&oauth\u version=1.0&oauth\u signature=xxx'

在这里。access.key.secret声明为“消费者机密”@herdeveloperSupport,我相信是的,是的。这里是。access.key.secret声明为“消费者机密”?@herdevelopersupport,我想是的。等等,你用了
HMAC-SHA1
?文档特别提到只允许
HMAC-SHA256
:@Adam,它对HMAC-SHA1或HMAC-SHA256都有效。在另一个房间和你分享卷发answer@HEREDeveloperSupport邮递员请求中的正文应该是什么?@Rut Shah,请在邮递员请求中指定grant_type=client_凭据。请参见上图。@sevelopersupport谢谢。我得到以下错误:{“errorId”:“error-21b4cee1-abcd-4f81-bab0-6aefa5855f70”,“httpStatus”:401,“errorCode”:401300,“消息”:“签名不匹配。授权签名或客户端凭据错误。”,“error”:“无效客户端”,“错误描述”:“错误代码:'401300'。签名不匹配。授权签名或客户端凭据错误。”}在授权中,我发送以下属性:使用者密钥(here.access.Key.id)、使用者机密(here.access.Key.Secret)签名方法为HMAC-SHA256wait,您使用了
HMAC-SHA1
?文档特别提到只允许
HMAC-SHA256
:@Adam,它对HMAC-SHA1或HMAC-SHA256都有效。在另一个文档中与您共享curlanswer@HEREDeveloperSupport邮递员请求中的正文应该是什么?@Rut Shah,请指定grant_type=邮递员请求中的客户端\凭据。请参见上图。@herdevelopersupport谢谢。我收到以下错误:{“errorId:“error-21b4cee1-abcd-4f81-bab0-6aefa5855f70”,“httpStatus”:401,“errorCode”:401300,“消息”:“签名不匹配。授权签名或客户端凭据错误。”,“error:”无效的客户端,“错误描述”:“错误代码:'401300'。签名不匹配。授权签名或客户端凭据错误。}在授权中,我发送以下属性:使用者密钥(here.access.Key.id)、使用者机密(here.access.Key.Secret)和HMAC-SHA256签名方法