2

i have problem with generate oAuth signature to Garmin Wellness API.

    $oauth_nonce = 'OhJBVADBAC8';
    $oauth_timestamp = '1614947339';
    $date_from = 1607089161;
    $date_to = 1614865161;

    $url = 'https://apis.garmin.com/wellness-api/rest/backfill/activities?summaryStartTimeInSeconds=' . $date_from . '&summaryEndTimeInSeconds=' . $date_to;

    $base_string = 'GET&' . rawurlencode($url) . '&' . rawurlencode('oauth_consumer_key=' . $oauth_consumer_key . '&oauth_nonce=' . $oauth_nonce . '&oauth_signature_method=' . $oauth_signature_method . '&oauth_timestamp=' . $oauth_timestamp . '&oauth_token=' . $oauth_token . '&oauth_version=' . $oauth_version . '&summaryStartTimeInSeconds=' . $date_from . '&summaryEndTimeInSeconds=' . $date_to);

    $oauth_signature = hash_hmac("SHA1", $base_string, $oauth_consumer_secret, false);
    $oauth_signature = rawurlencode(base64_encode(pack('H*', $oauth_signature)));

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HTTPHEADER => array(
            'Authorization: OAuth oauth_consumer_key="' . $oauth_consumer_key . '",oauth_token="' . $oauth_token . '",oauth_signature_method="' . $oauth_signature_method . '",oauth_timestamp="' . $oauth_timestamp . '",oauth_nonce="' . $oauth_nonce . '",oauth_version="' . $oauth_version . '",oauth_signature="' . $oauth_signature . '"'
        ),
    ));

    $response = curl_exec($curl);
    var_dump($response);
    curl_close($curl);

API returns "Invalid OAuth signature". When I put signature generated by Pastman, everything i s all right, so problem is in my way of generating signature.

Can you indicate my wrong?

mhc
  • 31
  • 5
  • [uday thammaneni](https://stackoverflow.com/users/10656095) posted an [Answer](https://stackoverflow.com/a/67053508) saying "Follow this link to connect with Garmin it worked. It uses the same Auth1.0a Authentication process [https://wordpress.stackexchange.com/questions/213006/how-to-use-oauth-authentication-with-rest-api-via-curl-commands](https://wordpress.stackexchange.com/questions/213006/how-to-use-oauth-authentication-with-rest-api-via-curl-commands)" – Scratte Apr 19 '21 at 10:34
  • Hi @mhc have you succeed integrating the Garmin API? – Ankur_009 Oct 06 '21 at 05:59

0 Answers0