Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a signature for amazon fps

I am working on integrating Amazon FPS into my company's website but seem to be having problems generating a proper signature. Here is what Amazon's documentation says to do: http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/APPNDX_GeneratingaSignature.html

Here is my string that I hash:

GET\nfps.sandbox.amazonaws.com\n/\nAction=Reserve&AWSAccessKeyId=REMOVED&CallerDescription=Reserve&CallerReference=CallerReference05&RecipientTokenId=254656Example83987&SenderTokenId=553IPMACGAZ2J4N1L7BJ3UMNRFTQU4V9NT4RJCTVADDJKXQ6L1ZAKSIUNPIRTTI1&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-09-12T22%3A29%3A07.623Z&TransactionAmount.CurrencyCode=USD&TransactionAmount.Value=1.00&Version=2010-08-28

and here is the HTTP request I send:

https://fps.sandbox.amazonaws.com?Action=Reserve&AWSAccessKeyId=REMOVED&CallerDescription=Reserve&CallerReference=CallerReference05&RecipientTokenId=254656Example83987&SenderTokenId=553IPMACGAZ2J4N1L7BJ3UMNRFTQU4V9NT4RJCTVADDJKXQ6L1ZAKSIUNPIRTTI1&Signature=t5r%2BWmV9PdoOGfHhtwLJ5nJ8zo%2BIJL4uWB6MOMpkZLw%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-09-12T22%3A29%3A07.623Z&TransactionAmount.CurrencyCode=USD&TransactionAmount.Value=1.00&Version=2010-08-28

Also here is the exact error I receive back:

SignatureDoesNotMatch 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. RequestID - ac476abb-2bc6-4891-8854-e52cf33f8716

I am writing this in coffeescript with a node.js backend. Can anyone find what I am doing wrong? I can post my code if needed.

like image 644
koruptpaintbaler Avatar asked Sep 12 '12 15:09

koruptpaintbaler


2 Answers

I figured out what I was doing wrong. My query fields were not in natural byte ordering. AWSAccessKey comes before Action. Amazon's example showed them the way I was trying to do it and not the correct way.

like image 133
koruptpaintbaler Avatar answered Oct 31 '22 13:10

koruptpaintbaler


I wrote a small lib to help with signing requests. maybe it could be useful to you https://github.com/theRemix/aws_signature_utils_js

like image 32
theRemix Avatar answered Oct 31 '22 11:10

theRemix