UNPKG

node-red-contrib-oauth2

Version:

The node-red-contrib-oauth2 is a Node-RED node that provides an OAuth2 authentication flow. This node uses the OAuth2 protocol to obtain an access token, which can be used to make authenticated API requests.

1 lines 9.25 kB
[{"id":"3db3b0fd97716db6","type":"tab","label":"Sandbox PayPal - Client Credentials","disabled":false,"info":"","env":[]},{"id":"77cb8766f3d0f394","type":"group","z":"3db3b0fd97716db6","style":{"stroke":"#252525","stroke-opacity":"1","fill":"#333333","fill-opacity":"0.5","label":true,"label-position":"nw","color":"#dedede"},"nodes":["ba4c69bc6934eaf0","56941dc7fa2c9109","ea5f619acb7c6975","c6338a46953ce90f","0f0959f25b8ffac2","d501a2a68aed65ff","74cb073642513c64","b438631713b789b3","ba9065365539726b","7ae923df938ff7c2","2c022952654e4a88","7b99c317fa69b979","50f21b0248ad11fa","1e9fe7a88f8a9fd5","9f0816024a976737","23fd9bb05a9e0890","a5913a06e02ebba5","e398f17b55741fad"],"x":14,"y":19,"w":1032,"h":488},{"id":"a5913a06e02ebba5","type":"group","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","style":{"stroke":"#2e333a","stroke-opacity":"1","fill":"#383c45","fill-opacity":"0.5","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["4a659fbacbd5a9ba","f7a09a555df4434c","4eb9ce10f8328334","ba768d993577dd9a","c22f0bf46fb98541"],"x":264,"y":359,"w":742,"h":122},{"id":"23fd9bb05a9e0890","type":"junction","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","x":620,"y":220,"wires":[["ba4c69bc6934eaf0"]]},{"id":"c22f0bf46fb98541","type":"junction","z":"3db3b0fd97716db6","g":"a5913a06e02ebba5","x":760,"y":440,"wires":[["ba768d993577dd9a","4eb9ce10f8328334"]]},{"id":"e398f17b55741fad","type":"junction","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","x":860,"y":160,"wires":[["ea5f619acb7c6975"]]},{"id":"ba4c69bc6934eaf0","type":"http request","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":730,"y":220,"wires":[["e398f17b55741fad"]]},{"id":"56941dc7fa2c9109","type":"function","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"POST credit-cards","func":"let token = global.get('token');\nmsg = {\n url: 'https://api.sandbox.paypal.com/v1/vault/credit-cards/',\n method: 'POST',\n headers: {\n content_type: 'application/json',\n authorization: `Bearer ${token}`\n },\n 'payload':{\n \"number\": \"4417119669820331\",\n \"type\": \"visa\",\n \"expire_month\": \"11\",\n \"expire_year\": \"2024\",\n \"first_name\": \"Joe\",\n \"last_name\": \"Shopper\",\n \"billing_address\": {\n \"line1\": \"52 N Main St.\",\n \"city\": \"Johnstown\",\n \"country_code\": \"US\",\n \"postal_code\": \"43210\",\n \"state\": \"OH\",\n \"phone\": \"408-334-8890\"\n }\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":140,"wires":[["23fd9bb05a9e0890"]]},{"id":"ea5f619acb7c6975","type":"debug","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":160,"wires":[]},{"id":"c6338a46953ce90f","type":"inject","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":140,"wires":[["56941dc7fa2c9109"]]},{"id":"0f0959f25b8ffac2","type":"function","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"set token","func":"global.set('token',msg.oauth2Response.access_token);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":120,"wires":[["e398f17b55741fad"]]},{"id":"d501a2a68aed65ff","type":"oauth2","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","container":"oauth2Response","grant_type":"client_credentials","access_token_url":"https://api.sandbox.paypal.com/v1/oauth2/token","username":"","password":"","client_id":"ATg1CMHw7GDbOH-XMd_IgzoksBNlvO_ieIyR-oBMoM_xiewyI7RrK8EOLMj438TAchfYtnVD6YeICHu2","client_secret":"EP2Xdc1ni1YGoT8EMiYPWQHhUDLrPM4oOitsEJShS4zmSKIEX0nfArtDtauxxhgnJd7BxLyOfEoIjow6","scope":"","headers":{},"x":450,"y":60,"wires":[["0f0959f25b8ffac2"]]},{"id":"74cb073642513c64","type":"inject","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":60,"wires":[["d501a2a68aed65ff"]]},{"id":"b438631713b789b3","type":"inject","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":220,"wires":[["ba9065365539726b"]]},{"id":"ba9065365539726b","type":"function","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"POST orders","func":"let token = global.get('token');\nmsg = {\n url: 'https://api-m.sandbox.paypal.com/v2/checkout/orders',\n method: 'POST',\n headers: {\n 'Content-type': 'application/json',\n 'Authorization': `Bearer ${token}`\n },\n 'payload':{\n \"intent\": \"CAPTURE\",\n \"purchase_units\": [\n {\n \"amount\": {\n \"currency_code\": \"USD\",\n \"value\": \"100.00\"\n }\n }\n ]\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":220,"wires":[["23fd9bb05a9e0890"]]},{"id":"7ae923df938ff7c2","type":"inject","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":260,"wires":[["2c022952654e4a88"]]},{"id":"2c022952654e4a88","type":"function","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"GET invoices","func":"let token = global.get('token');\nmsg = {\n url: 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true',\n method: 'GET',\n headers: {\n content_type: 'application/json',\n authorization: `Bearer ${token}`\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":260,"wires":[["23fd9bb05a9e0890"]]},{"id":"7b99c317fa69b979","type":"function","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"POST generate-next-invoice-number","func":"let token = global.get('token');\nmsg = {\n url: 'https://api-m.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number',\n method: 'POST',\n headers: {\n content_type: 'application/json',\n authorization: `Bearer ${token}`\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":180,"wires":[["23fd9bb05a9e0890"]]},{"id":"50f21b0248ad11fa","type":"inject","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":180,"wires":[["7b99c317fa69b979"]]},{"id":"1e9fe7a88f8a9fd5","type":"function","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"GET webhooks","func":"let token = global.get('token');\nmsg = {\n url: 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks',\n method: 'GET',\n headers: {\n content_type: 'application/json',\n authorization: `Bearer ${token}`\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":300,"wires":[["23fd9bb05a9e0890"]]},{"id":"9f0816024a976737","type":"inject","z":"3db3b0fd97716db6","g":"77cb8766f3d0f394","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":300,"wires":[["1e9fe7a88f8a9fd5"]]},{"id":"4a659fbacbd5a9ba","type":"http in","z":"3db3b0fd97716db6","g":"a5913a06e02ebba5","name":"","url":"/webhook","method":"post","upload":false,"swaggerDoc":"","x":380,"y":440,"wires":[["f7a09a555df4434c"]]},{"id":"f7a09a555df4434c","type":"function","z":"3db3b0fd97716db6","g":"a5913a06e02ebba5","name":"x-real-ip","func":"let ips = global.get('x-ip') || {};\n\nif ( msg.req.headers.host != \"localhost:1880\") {\n \n if (msg.req.headers[\"x-real-ip\"] in ips){\n ips[msg.req.headers[\"x-real-ip\"]] = ips[msg.req.headers[\"x-real-ip\"]] + 1;\n } else {\n ips[msg.req.headers[\"x-real-ip\"]] = 1;\n }\n \n global.set('X-Forwarded-For', msg.req.headers[\"X-Forwarded-For\"]);\n global.set('x-ip', ips);\n \n msg.payload = msg.req.headers[\"x-real-ip\"];\n msg.ip = msg.req.headers[\"x-real-ip\"];\n \n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":440,"wires":[["c22f0bf46fb98541"]],"icon":"node-red/alert.svg"},{"id":"4eb9ce10f8328334","type":"http response","z":"3db3b0fd97716db6","g":"a5913a06e02ebba5","name":"","statusCode":"200","headers":{},"x":920,"y":440,"wires":[]},{"id":"ba768d993577dd9a","type":"debug","z":"3db3b0fd97716db6","g":"a5913a06e02ebba5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":400,"wires":[]}]