Oauth signature failed for withings API

661 Views Asked by At

I am working to integrate my application with the Withings api with spring rest template.

But,while generating the Oauth signature I am getting the "Invalid signature". I am trying to devise a signature according to the API specification but I am not able to generate it successfully. I have mentioned the code that I used. Please, provide me some solutions.

private String generateSignature(String baseString, String secret) throws          UnsupportedEncodingException {
    String secretKey = consumerSecret + "&";


    SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
    HMAC_SHA1SignatureMethod hmacsha = new HMAC_SHA1SignatureMethod(keySpec);
    String signatureString = hmacsha.sign(baseString);
    String base64Encode = new String((signatureString.getBytes()));
    signature = URLEncoder.encode(base64Encode, "UTF-8");

For reference, http://oauth.withings.com/api

1

There are 1 best solutions below

0
Charles-Antoine Fournel On

i faced the same issues before , it seems the signature need you params ( api params + oauth params ) to be ordered alphabetically .

You need also to give a correct secret word in making you signature based uri .

you can check if you want my php oauth lib ( more particulary in AbstractService.php ) for withing here https://github.com/huitiemesens/PHPoAuthLib ( it s a fork of the original phpoauthlib with specific order for withings apis ... )