2
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'],
  'user_agent' => 'test (Language=Ruby)',
  '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です

誰でもこれで私を助けることができます

4

1 に答える 1