From ccd58381fd09773610a4fb1351797d974e152561 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 10:07:32 -0400 Subject: [PATCH 01/22] test --- src/security.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/security.js b/src/security.js index 8ef7216..2448f23 100755 --- a/src/security.js +++ b/src/security.js @@ -3,6 +3,8 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ + +// pliny1-branch test var jwt = require('jwt-simple'); module.exports = function(req, res, next) { From f58c19827c318c80af7a8f1f76a17c1e95b6a994 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 11:49:39 -0400 Subject: [PATCH 02/22] test --- src/security.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security.js b/src/security.js index 2448f23..b13437e 100755 --- a/src/security.js +++ b/src/security.js @@ -4,7 +4,7 @@ MIT Licensed */ -// pliny1-branch test +// pliny1-branch test var jwt = require('jwt-simple'); module.exports = function(req, res, next) { From 83d6f47998b278b0bd08513bc2d18e1d0346dcce Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 12:40:55 -0400 Subject: [PATCH 03/22] add --- src/another.js | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100755 src/another.js diff --git a/src/another.js b/src/another.js new file mode 100755 index 0000000..b13437e --- /dev/null +++ b/src/another.js @@ -0,0 +1,123 @@ +/*! + * https://www.instapio.com + * Copyright(c) 2013-2017 Instapio, Inc + MIT Licensed +*/ + +// pliny1-branch test + +var jwt = require('jwt-simple'); +module.exports = function(req, res, next) { + try { + if (req.query.jwt !== undefined || req.query.state !== undefined) { + var token = ""; + if (req.query.jwt !== undefined) { + token = req.query.jwt + } + if (req.debug) req.debug("JWT Token:" + token); + req.vars = jwt.decode(token, global.config.INSTAPIO_CLIENT_SECRET); + res.locals.TOKEN = token; + var keys = Object.keys(req.vars); + for (var i = 0; i < keys.length; i++) { + res.locals[keys[i]] = req.vars[keys[i]]; + } + res.locals.INSTAPIO_SDKJS = req.vars.environment_url + "/assets/instapio_sdk.js"; + if (req.vars.environment_name && req.vars.environment_url) { + console.log("Checking Environments Cache"); + var env_name = req.vars.environment_name; + var env_url = req.vars.environment_url; + if (req.cache && req.cache.get) { + console.log("Checking Environments In Cache"); + req.cache.get("environments", function(err, environments) { + console.log("Checking Environments Cache Result" + JSON.stringify(environments)); + if (err || environments === undefined || environments == null) { + console.log("Checking Environments Not In Cache"); + req.db.load('all', 'environments', 'environments', function(err, env_entity) { + console.log("Checking Environments Loaded from DB"); + if (env_entity === undefined || environments == null) { + console.log("Checking Environments Not Defined in DB"); + env_entity = { environments: {} } + } + console.log(env_entity); + if (env_entity.environments === undefined) env_entity.environments = {}; + console.log("Checking Environments Setting Object"); + env_entity.environments[env_name] = env_url; + req.db.save('all', 'environments', 'environments', env_entity, function(err) { + console.log("Checking Environments Saved DB"); + req.cache.set("environments", env_entity.environments, function(err) { + console.log("Checking Environments Saved Cache"); + }) + }) + }) + } else { + if (environments[env_name] === undefined) { + req.db.load('all', 'environments', 'environments', function(err, env_entity) { + console.log("Checking Environments Loaded from DB"); + if (environments === undefined) { + console.log("Checking Environments Not Defined in DB"); + env_entity = { environments: {} } + } + if (env_entity.environments === undefined) env_entity.environments = {}; + console.log("Checking Environments Setting Object"); + env_entity.environments[env_name] = env_url; + req.db.save('all', 'environments', 'environments', env_entity, function(err) { + console.log("Checking Environments Saved DB"); + req.cache.set("environments", env_entity.environments, function(err) { + console.log("Checking Environments Saved Cache"); + }) + }) + }) + } + } + + }) + } + } + if (req.debug) req.debug("JWT Data:" + JSON.stringify(req.vars)); + if (global.config.OAUTH !== "" && req.baseUrl != "/oauth") { + req.db.account.load(req.vars.environment_name, req.vars.account_id, function(err, account) { + req.debug("Account Loaded:"); + req.debug(account); + if (global.app.oauth_verify !== undefined) { + global.app.oauth_verify(req, account, function(err) { + if (err) { + res.render('oauth_required', { token: token }); + return; + } + next(); + }); + } else { + if (account !== undefined && account.access_token !== undefined && account.access_token !== null && account.access_token != "") { + next(); + } else { + res.render('oauth_required', { token: token }); + } + } + }) + } else { + next(); + } + } else { + if (req.body !== undefined && req.body.push_secret !== undefined) { + if (req.debug) req.debug("Push Secret Authentication"); + if (req.body.push_secret == global.config.INSTAPIO_PUSH_SECRET) { + if (req.debug) req.debug("Push Secret Authenticated"); + return next(); + } + } + res.render('oauth_fail'); + } + } catch (e) { + if (req.error !== undefined) { + req.error("Exception in JWT"); + req.error(e); + } else { + console.log("Exception in JWT"); + console.log(e); + } + res.render('oauth_fail'); + + } +} + +module.exports(); From 086dc8d44ce7b7a0fed10a31b56ebb3def5220b8 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 13:59:12 -0400 Subject: [PATCH 04/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index b13437e..9bbb294 100755 --- a/src/another.js +++ b/src/another.js @@ -4,7 +4,7 @@ MIT Licensed */ -// pliny1-branch test +// pliny1-branch test var jwt = require('jwt-simple'); module.exports = function(req, res, next) { From 1afc322bc2d8063786681a95a25769052e7cc31d Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:00:26 -0400 Subject: [PATCH 05/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 9bbb294..892e8ee 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 48e6c7e1f056df95048185d43c604540000ca8e1 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:01:37 -0400 Subject: [PATCH 06/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 892e8ee..0569a3c 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 0645e9fe562dcbbc670261dfab86e91548b0356f Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:02:13 -0400 Subject: [PATCH 07/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 0569a3c..7636e58 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 6471b7bb2653ad0e07c3f30d21f9dbbe02b5a466 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:03:15 -0400 Subject: [PATCH 08/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 7636e58..892e8ee 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 68ba1c3b6e05c38ddc88220d958daa3ace7fccde Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:10:51 -0400 Subject: [PATCH 09/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 892e8ee..0569a3c 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 7efc51d9fe409518beb212fb27517e054b1f5914 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:11:40 -0400 Subject: [PATCH 10/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 0569a3c..7636e58 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From bee475db699f009b90e500c4512f236532afba7d Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:13:07 -0400 Subject: [PATCH 11/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 7636e58..1bb0935 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From af817b44181ef41dd0754d3a9c316372459d7d30 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:13:43 -0400 Subject: [PATCH 12/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 1bb0935..9bbb294 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 5a5220e4f6744291c6cc85e43ff99905f6b8a1e1 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:14:27 -0400 Subject: [PATCH 13/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 9bbb294..892e8ee 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 647008eb4b8c54c8d2b5340b729e7dae5e0e6bea Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Sun, 2 Jun 2019 14:15:25 -0400 Subject: [PATCH 14/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 892e8ee..0569a3c 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 73378a77f83c16e5e3c380bd8dbc08c6f9ef21e4 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 11:52:16 -0400 Subject: [PATCH 15/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 0569a3c..595a5aa 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 9bbe1c9ef4e24476eb9217e9a3e1c98d387fff34 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 11:55:26 -0400 Subject: [PATCH 16/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 595a5aa..892e8ee 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From 8053b29256eae931c81a1558a2596417d53dd591 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 11:58:33 -0400 Subject: [PATCH 17/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 892e8ee..7636e58 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From ec40899d32513afbb9fab62e8b78cf258bb9c482 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 12:12:03 -0400 Subject: [PATCH 18/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 7636e58..1bb0935 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From e3ab0917e7699ecf2b696dce0cc32c5d7db338f7 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 12:16:27 -0400 Subject: [PATCH 19/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 1bb0935..be03516 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test var jwt = require('jwt-simple'); From f8a400d07c85b455a6c885dfa999599eb4650866 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 13:13:43 -0400 Subject: [PATCH 20/22] test --- src/another.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/another.js b/src/another.js index be03516..6777b1d 100755 --- a/src/another.js +++ b/src/another.js @@ -5,6 +5,7 @@ */ // pliny1-branch test + var jwt = require('jwt-simple'); module.exports = function(req, res, next) { From 17b2462eeff5fb5cfd00f96e20a2c9f28f383287 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 13:15:50 -0400 Subject: [PATCH 21/22] test --- src/another.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/another.js b/src/another.js index 6777b1d..2232602 100755 --- a/src/another.js +++ b/src/another.js @@ -3,7 +3,7 @@ * Copyright(c) 2013-2017 Instapio, Inc MIT Licensed */ - + // pliny1-branch test From 019a7a079b361cb21d2bd5420ed6ad4b2a0b0d34 Mon Sep 17 00:00:00 2001 From: "jisheng.zhao" Date: Tue, 4 Jun 2019 13:16:30 -0400 Subject: [PATCH 22/22] test --- src/another.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/another.js b/src/another.js index 2232602..0569a3c 100755 --- a/src/another.js +++ b/src/another.js @@ -5,7 +5,6 @@ */ // pliny1-branch test - var jwt = require('jwt-simple'); module.exports = function(req, res, next) {