I am trying to access Amazon's Product Advertising API in my iOS application. Creating the signature seems to be the tough part. On this page:
http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/rest-signature.html
It says to "Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm". Amazon also provides a java class to do this for you:
http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/AuthJavaSampleSig2.html
Does anybody know how I can do this in Objective-C instead? I looked into the AWS iOS SDK, but it doesn't seem to include the Product Advertising API.
Swift 2.0
Here is a function that will sign a set of parameters for Swift. Note that this code requires the
Alamofire
andAWSCore
Cocoapods to be installed. You also need to add#import <CommonCrypto/CommonCrypto.h>
to your Objective-C Bridging header otherwisekCCHmacAlgSHA256
won't be found.It's called like this:
Finally, the timestampFormatter is declared like this:
You can use/modify to suit your needs, but everything that's necessary should be there.
Instead of using CommonCrypto, which is deprecated in modern OS X, you can also use SecTransforms:
A few steps missing from P-double post.
Prior to constructing the unsigned string, you will need to get the Timestamp value in place.
Once the date is url friendly encoded, the rest of the steps works like a charm.
Lastly, I also used CFURLCreateStringByAddingPercentEscapes listed above to encode the string generated by the AmazonAuthUtils HMACSign message call.
Actually the AWS iOS SDK DID have a static method to handle all auth situations. Maybe you should take a glance at the
AmazonAuthUtils.h
:you can find it in the document: http://docs.amazonwebservices.com/AWSiOSSDK/latest/Classes/AmazonAuthUtils.html
Am I wrong that it is not 'legal' (according to Amazon's own guidelines) to use Amazon's Product Advertising API in an iOS app without Amazon's express written consent?
Check out my Amazon Product Advertising Client https://github.com/m1entus/RWMAmazonProductAdvertisingManager
Some code with requesst serialization: