为什么会收到“签名不匹配。授权签名或事物凭证错误”的信息?

时间:2019-05-19 11:00:54

标签: here-api

尝试为设备生成令牌,但出现“”签名不匹配。授权签名或事物凭证错误” 不确定我做错了什么

发送带有标头的POST请求: 内容类型:application / json 授权:OAuth的oauth_consumer_key = “ac85020f-c352-4ac9-853e-4b64f3645463”,oauth_signature_method = “HMAC-SHA256”,oauth_timestamp = “1558262091”,oauth_nonce = “LIIBLApk88”,oauth_version = “1.0”,oauth_signature = “e894d7545b903c16723c1051305828efc52623da534197a50d782f82b9f0149c”

oauth签名是以下地址的HMAC-SHA256:POST&https%3A%2F%2Ftracking.api.here.com%2Fv2%2Ftoken&oauth_consumer_key%3Dac85020f-c352-4ac9-853e-4b64f3645463%26oauth_nonce%3DLIIBLApk_5%-odd 26oauth_timestamp%3D1558260025%26oauth_version%3D1.0

签名如下:{Device secret}&

并获得: {     “代码”:401,     “ id”:“ 624b4eb2-7838-450d-8c5c-363c3df4f308”,     “ message”:“签名不匹配。授权签名或事物凭证错误。”,     “ error”:“ 时间戳错误 \ n \ n如果请求时间戳与\ nserver时间相差超过10秒,则将带有当前服务器的x-here-timestamp标头\ ntimestamp添加到\ n \ n 不正确的签名 \ n \ n如果OAuth签名不正确,则响应将是401但\ n 没有x-here-timestamp字段。\ n“ }

timpestamp没错

4 个答案:

答案 0 :(得分:1)

您的oauth签名中缺少一些。我遇到过同样的问题。它应该看起来像

POST&https%3A%2F%2Faccount.api.here.com%2Foauth2%2Ftoken&grant_type%3Dclient_credentials%26oauth_consumer_key%3Dxxxxxxxxxxxxxxxx%26oauth_nonce%3D5e5c338b14198%26oauth_signature_method%3DHMAC-SHA256%26oauth_timestamp%3D1583100811%26oauth_version%3D1.0

在“令牌”之后,您丢失了grant_type%3Dclient_credentials

答案 1 :(得分:0)

如果有人遇到类似情况,则需要从URLEncoding中排除Host和params之间的&之间(以及POST之后):

'POST&' + encodeURIComponent('https://account.api.here.com/oauth2/token') + '&' + encodeURIComponent(paramString);

答案 2 :(得分:0)

一旦有了访问密钥和签名,就可以使用令牌REST API请求令牌。典型的请求包括以下元素:

URL https://account.api.here.com/oauth2/token

HTTP标头

Content-Type:应用程序/ x-www-form-urlencoded 授权:OAuth oauth_consumer_key =“”, oauth_nonce =“”, oauth_signature =“”, oauth_signature_method =“ HMAC-SHA256”, oauth_timestamp =“”, oauth_version =“ 1.0”

请求正文

请求正文必须包含: grant_type = client_credentials

注意:grant_type的值必须始终为client_credentials。

答案 3 :(得分:0)

  • 我遇到了同样的问题。我在标头时发现 URL 不匹配 签名生成和 api 调用 URL。所以我想你错过了或 添加一些东西,比如空间或其他你需要的小东西 再次重新检查您的代码并仔细验证。我确定它有效 给你。