0

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?

2 Answers 2

1

Please read about set request header: XMLHttpRequest.setRequestHeader

XMLHttpRequest.setRequestHeader(header, value)

you can use XMLHttpRequest.setRequestHeader API to set header for any request.

For OAuth you can read more: OAuth.

In your case to implement OAuth to get the token

POST /oauth/initiate

The following request parameters should be present in the Authorization header:

oauth_callback - an URI to which the Service Provider will redirect the resource owner (user) after the authorization is complete.
oauth_consumer_key - the Consumer Key value, retrieved after the registration of the application.
oauth_nonce - a random value, uniquely generated by the application.
oauth_signature_method - name of the signature method used to sign the request. Can have one of the following values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT.
oauth_signature - a generated value (signature).
oauth_timestamp - a positive integer, expressed in the number of seconds since January 1, 1970 00:00:00 GMT.
oauth_version - OAuth version.

Good Luck! :)

Sign up to request clarification or add additional context in comments.

Comments

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.