Alin Ben Hemo Alin Ben Hemo - 4 days ago 5
Javascript Question

javascript xmlhttprequest Authorization magento oauth

I'm cant understand how to user authorization headers in vanila javascript.

guide magento rest-api (oAuth 1.0),
https://github.com/nickvane/Magento-RestApi/wiki/Authentication-steps.

how i implement this headers in my code:
POST /oauth/initiate

Authorization: OAuth oauth_callback="http%3A%2F%2Flocalhost%3A8888",oauth_consumer_key="YOUR-CONSUMER-KEY",oauth_nonce="t02auly6elcuthly",oauth_signature="7FMe1UducbDUgCJWQY4Avv3g3f4%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1371098086",oauth_version="1.0"


my code:

var ajax = new XMLHTTPREQUEST();
ajax.open('POST', myurl+'/oauth/initiate',true);
ajax.send();
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 ){

console.log(ajax.responseText);
}
}


how i can add headers like this to my code?

Answer

Please try to use this:

ajax.setRequestHeader('Authorization','OAuth oauth_callback="http%3A%2F%2Flocalhost%3A8888",oauth_consumer_key="86a507bfc290e0cfa0e1813f555f1cb2",oauth_nonce="9c89f47ef962a69f7666a35e27d9e7da",oauth_signature="8lqJ6/hOPUeYFpKtuVGilg3lmew=",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1477181081",oauth_version="1.0"')
Comments