我正在使用 aws-sigv4 gem 来创建签名,但出现错误

问题描述

require 'aws-sigv4'

signer = Aws::sigv4::Signer.new(access_key_id: access_key,region: 'us-east-1',secret_access_key: secret_key,service: 'execute-api')

signature = signer.sign_request(
  http_method: 'GET',url: 'https://sandBox.sellingpartnerapi-na.amazon.com/Feeds/2021-06-30/Feeds',headers: {
    'host' => 'sellingpartnerapi-na.amazon.com','user_agent' => 'test (Language=Ruby)','x-amz-access-token' => access_token
  })

 response = HTTParty.send(:get,'https://sandBox.sellingpartnerapi-na.amazon.com/Feeds/2021-06-30/Feeds',headers: {
  'host' => signature.headers['host'],'x-amz-access-token' => access_token,'x-amz-content-sha256' => signature.headers['x-amz-content-sha256'],'x-amz-date' => signature.headers['x-amz-date'],'Authorization' => signature.headers['authorization'],})

我收到以下错误

#<HTTParty::Response:0x55a044ec7c98 parsed_response={"errors"=>[{"message"=>"Access to requested resource is denied.","code"=>"Unauthorized","details"=>"Access token is missing in the request header."}]},@response=#<Net::HTTPForbidden 403 Forbidden readbody=true>,@headers={"date"=>["Mon,12 Jul 2021 09:16:40 GMT"],"content-type"=>["application/json"],"content-length"=>["187"],"connection"=>["close"],"x-amzn-requestid"=>["db0c65ea-f15a-4532-aadb-532b0eb1c6f2"],"x-amzn-errortype"=>["AccessDeniedException"],"x-amz-apigw-id"=>["CWZCzHploAMF6oA="]}>

当我尝试使用带有我在上面生成的签名的邮递员点击请求时,出现以下错误

{
    "errors": [
        {
            "message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\n\nThe Canonical String for this request should have been\n'GET\n/Feeds/2021-06-30/Feeds\n\ncontent-type:\nhost:sandBox.sellingpartnerapi-na.amazon.com\nx-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nx-amz-date:20210712T140633Z\n\ncontent-type;host;x-amz-content-sha256;x-amz-date\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'\n\nThe String-to-Sign should have been\n'AWS4-HMAC-SHA256\n20210712T140633Z\n20210712/us-east-1/execute-api/aws4_request\n5c4a3c5b6bfb8d42b8f45993ff0ba1fa49d82b1b182e6da616bd6ae5f7e98ffd'\n","code": "InvalidSignature"
        }
    ]
}

这是屏幕截图或https://prnt.sc/1al04od

谁能帮我解决这个问题

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)