Im using oauth-signature to generate my oauth-signature for connection with woocommerce api. I followed all the steps stated at woocommerce rest api documentation:
I did finally get it working.
Somehow it wouldnt work for my local wordpress installation, but it did work for my live wordpress site:
Angular2 code:
constructor(private http: Http) {
var oauth = OAuth({
consumer: {
key: 'ck_...',
secret: 'cs_...'
},
signature_method: 'HMAC-SHA1',
hash_function: function(base_string, key) {
return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
}
});
var requestData = {
url: 'http://siglarweb.no/wp-json/wc/v1/orders',
method: 'GET'
};
this.http.get(
requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
).subscribe(data => {
console.log(data);
});
}
libraries used (installed via npm):
npm install crypto-js --save npm install oauth-1.0a --save
Required files:
"scripts": [
"../node_modules/crypto-js/crypto-js.js",
"../node_modules/oauth-1.0a/oauth-1.0a.js"
]
We have met issues with a 401 unauthorised
response with response code like woocommerce_rest_invalid_signature
.
And it turns out that the URL we used when hashing is different from the URL we accessed, the URL used in the hash is missing the trailing slash.