paypal - Generating Authentication Header -
is there way generate authentication header third party through not using paypal sdk. have gotten access token , secret. these have been through curl requests have been straightforward me. there anyway this?
in addition, generate header need api signature of third party? how this?
thank help.
for else looking node.js solution paypal x-paypal-authorization header values, wrote this:
function paypalurlencoder(s) { var hex = "0123456789abcdef"; var untouched = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890_"; var result = s.split('').map(function(c){ if (untouched.indexof(c)>=0) { return c; } else if (c==' ') { return "+"; } else { // needs converting hex var code = c.charcodeat(0); return "%" + hex.charat((code & 0xf0) >> 4) + hex.charat(code & 0xf); } }); return result.join(''); } exports.authorizationtoken = function(accesstoken,method,endpoint) { var param_delimeter = "&"; var param_seperator = "="; var token = { key : accesstoken.token, secret : accesstoken.tokensecret}; var consumer = { key : global.config.paypal.username, secret : global.config.paypal.password }; // add params var params = { "oauth_consumer_key" : consumer.key, "oauth_version" : "1.0", "oauth_signature_method" : "hmac-sha1", "oauth_token" : token.key, "oauth_timestamp" : math.round(new date().gettime() / 1000), }; // convert params paramstring var paramkeys = []; var paramstring = ""; (var p in params) { paramkeys.push(p); } paramkeys.sort(); (var i=0; i<paramkeys.length; i+=1) { var p = paramkeys[i]; paramstring += (p + param_seperator + params[p]); if (i+1<paramkeys.length) paramstring += param_delimeter; } // create signature var key = paypalurlencoder(consumer.secret) + param_delimeter + paypalurlencoder(token.secret); var signaturebase = method + param_delimeter + paypalurlencoder(endpoint) + param_delimeter + paypalurlencoder(paramstring); var signature = cryptojs.hmacsha1(signaturebase, key).tostring(cryptojs.enc.base64); return "token="+token.key+",signature="+signature+",timestamp="+params["oauth_timestamp"]; };
authtoken returned call "/permissions/getaccesstoken" using usual methods , contains token , tokensecret pair operating on behalf of third party. method post , end point "https://svcs.sandbox.paypal.com/permissions/getbasicpersonaldata".
using method above might this:
exports.basicdetails = function(accesstoken, callback) { var http = require('https'); var host = global.config.paypal.sandbox ? 'svcs.sandbox.paypal.com' : 'svcs.paypal.com'; var path = '/permissions/getbasicpersonaldata'; var options = { host: host, path: path, method: 'post', headers: { "x-paypal-authorization" : exports.authorizationtoken(accesstoken,"post","https://"+host+path), "x-paypal-request-data-format" : "nv", "x-paypal-response-data-format" : "json", "x-paypal-application-id" : global.config.paypal.sandbox ? "<<yourappidsandbox>>" : "<<yourappid>>", }, }; var req = http.request(options, function(res){ var str = ""; res.setencoding('utf8'); res.on('data', function (chunk) { str += chunk; }); res.on('end', function () { if (callback) callback(false,json.parse(str)); }); }); req.on('error',function(e){ if (callback) callback("unable connect paypal"); }); req.end("attributelist.attribute(0)=http://axschema.org/contact/email&attributelist.attribute(1)=http://schema.openid.net/contact/fullname&requestenvelope.errorlanguage=en_us"); };
Comments
Post a Comment