aws-samples / sigv4a-signing-examples

Code examples in various frameworks for creating requests using the AWS SigV4a protocol
MIT No Attribution
56 stars 23 forks source link

Example 4 - Full example to get signed headers and make an API call #5

Closed sunabako closed 8 months ago

sunabako commented 1 year ago

I receive the following error when using this example; where am I supposed to add my AccessKeyId and SecretAccessKey and SessionToken which are required when making SP-API calls.

I used the same code as Example 4, I only edited the service, region, method, and url.

status_code: 403 
object text: {
  "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.
## Omitting for security reasons ##
",
     "code": "InvalidSignature"
    }
  ]
}
lovaarte commented 1 year ago

Which language did you use? Your credentials are used by AWS SDK when you sign the URL (e.g. not during the actual HTTP request). The way/order the credentials are used is as per SDK docs.

billbarni commented 1 year ago

I am getting 403 all the time in Java. Cant do a Lambda call with signed headers.

If the payload is null, everything goes fine with the Signer... but as soon it's an HTTP.Post and has a body, authentication fails.

I am searching all around the internet on how to make a Java call exactly as Postman does it with AWS Authentication, and even the AWS SDK fails. This SDK changes all the time, does not match documentation, has a release every week...

How to do a simple authentication of a Post call that Postman itself does? That I copy the structure? That I do the hash for the signature of the body... everything... I tried so much...

I followed the docs. This is so strange behavior.

I tried not setting a signature for the body and used the "fixed empty body" one that Postman uses: "beaead3198f7da1e70d03ab969765e0821b24fc913697e929e726aeaebf0eba3"

And it still gives a sign-error in Post calls with Body in Java.

Please fix this.

lovaarte commented 8 months ago

@billbarni Apologies for letting it hang for a while. I added example in java how to upload data/file through MRAP into S3 bucket. Note, it's a PUT request and not POST.

If you can't successfully derive the example to your specific use case, please provide specific details about your code and anything else relevant. For now, I'll close the issue if that doesn't address your use case.