You need to sign in to do that
Don't have an account?
SIgnature issue in Amazon SNS API
Hi All,
I am facing one issue since two weeks .The issue is i am not able to authenticate the amazon SNS Rest request properly and getting the following error.
Error:The request signature we calculated does not match the signature you provided.Check your key and signing method.
Follwoing is my code:
String date1=json.serialize(Datetime.now());
if(date1.contains('"'))
date1=date1.replace('"','');
date1=date1.substring(0,(date1.length()-4));
date1=date1+'000Z';
string url;
integer statuscode;
String algorithmName = 'HmacSHA256';
//date1=EncodingUtil.UrlEncode(date1,'UTF-8');
System.debug('##############date1final########'+date1);
String Hostname='sns.us-east-1.amazonaws.com';
String query='AWSAccessKeyId=XXXXXXXXXXXXXX&Action=CreateTopic&Name=Testtopics&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp='+date1+'&Version=2010-03-31';
string str='GET\n'+Hostname+'\n'+'/'+'\n'+query;
//str=EncodingUtil.UrlEncode(str,'UTF-8');
System.debug('%%%%%str%%%%%%'+str);
Blob mac = Crypto.generateMac(algorithmName,Blob.valueOf(str),Blob.valueOf(EncodingUtil.UrlEncode('XXXXXXX','UTF-8')));
url='http://'+Hostname+'/?'+'Action=CreateTopic&Name=Testtopics&AWSAccessKeyId=XXXXXXXXXXXXXX&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp='+date1+'&Signature='+EncodingUtil.UrlEncode(EncodingUtil.base64Encode(mac),'UTF-8');
System.debug('%%%%%url%%%%%%'+url);
http h=new http();
Httprequest req=new Httprequest();
Httpresponse res=new Httpresponse();
req.setEndpoint(url);
req.setMethod('GET');
res = h.send(req);
statuscode=res.getStatusCode();
string resp=res.getBody();
Hey Alka,
The following thread talks about this error, I see a couple of suggestions have been given thumbsup - worth a read:
http://stackoverflow.com/questions/2777078/amazon-mws-request-signature-calculated-does-not-match-the-signature-provided