ddo / oauth-1.0a

OAuth 1.0a Request Authorization for Node and Browser
MIT License
325 stars 116 forks source link

oauth_consumer_key="undefined" in request headers #89

Closed stanshivam closed 5 years ago

stanshivam commented 5 years ago

I am trying to hit an api which requires oAuth1.0. But, In request headers I see oauth_consumer_key="undefined". And request fails with 404. Am I missing something?

const url = `${WP_API_URL}/register`;
    const oauth = OAuth({
      consumer: {
        public: customer_key,
        secret: customer_secret
      },
      signature_method: 'HMAC-SHA1',
      hash_function(base_string, key) {
        return crypto
          .createHmac('sha1', key)
          .update(base_string)
          .digest('base64');
      }
    });
    const request_data = {
      url: url,
      method: 'POST'
    };
    return fetch(url, {
      method: 'POST',
      headers: { ...oauth.toHeader(oauth.authorize(request_data)) },
      body: JSON.stringify(data)
    })
      .then(function(response) {
        console.log(response);
        if (response.status !== 200) {
          console.log(
            'Looks like there was a problem. Status Code: ',
            response.status
          );
          return;
        }
        return response.json();
      })
      .catch(err => console.log(err));
stanshivam commented 5 years ago

Needed to send key property instead of public, in consumer object.