From 3b25babbeca3c0ac9a377cb72d38414ba2d2963a Mon Sep 17 00:00:00 2001 From: Kat Leight Date: Tue, 6 Apr 2021 16:42:54 -0600 Subject: [PATCH 1/2] update secret --- app.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index e677538..c2ef684 100644 --- a/app.js +++ b/app.js @@ -109,6 +109,9 @@ app.post('/register-and-broadcast-node', authenticate, function (req, res) { } + const id = req.token_id + const payload = { id } + const secret = "BootsAndBuffaloSauce" const registerNodes = [] BelayChain.networkNodes.forEach(networkNode => { @@ -141,7 +144,7 @@ app.post('/register-and-broadcast-node', authenticate, function (req, res) { app.get('/concensus', authenticate, function (req, res) { const id = req.token_id const payload = { id } - const secret = "BoobsAndBuffaloSauce" + const secret = "BootsAndBuffaloSauce" jwt.sign(payload, secret, (error, token) => { if (error) throw new Error("Signing Token didn't work") @@ -295,7 +298,7 @@ app.post('/verify', function (req, res) { function authenticate(request, response, next) { - const secret = "BoobsAndBuffaloSauce" + const secret = "BootsAndBuffaloSauce" const authHeader = request.get("Authorization") if (!authHeader) { From 5f00d6a8997262d7afb24a17724ae04a1033bef0 Mon Sep 17 00:00:00 2001 From: Kat Leight Date: Tue, 6 Apr 2021 16:52:46 -0600 Subject: [PATCH 2/2] auth successfully added to register nodes --- app.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index c2ef684..df799d0 100644 --- a/app.js +++ b/app.js @@ -60,7 +60,7 @@ const loadBelayChain = () => { } -app.post('/register-node', function (req, res) { +app.post('/register-node', authenticate, function (req, res) { const nodeURL = req.body.nodeURL if (BelayChain.networkNodes.indexOf(nodeURL) === -1 @@ -76,7 +76,7 @@ app.post('/register-node', function (req, res) { }) -app.post('/register-bulk-nodes', function (req, res) { +app.post('/register-bulk-nodes', authenticate, function (req, res) { const networkNodes = req.body.networkNodes pushNodes(networkNodes) @@ -112,31 +112,38 @@ app.post('/register-and-broadcast-node', authenticate, function (req, res) { const id = req.token_id const payload = { id } const secret = "BootsAndBuffaloSauce" + + jwt.sign(payload, secret, (error, token) => { + if (error) throw new Error("Signing Token didn't work") - const registerNodes = [] - BelayChain.networkNodes.forEach(networkNode => { - const requestOptions = { - uri: networkNode + '/register-node', - method: 'POST', - body: { nodeURL: nodeURL }, - json: true - } + const registerNodes = [] + BelayChain.networkNodes.forEach(networkNode => { + const requestOptions = { + uri: networkNode + '/register-node', + method: 'POST', + body: { nodeURL: nodeURL }, + headers: { 'Authorization': token }, + json: true + } - registerNodes.push(reqPromise(requestOptions)) - }) + registerNodes.push(reqPromise(requestOptions)) + }) - Promise.all(registerNodes) + Promise.all(registerNodes) .then(data => { const bulkRegisterOptions = { uri: nodeURL + '/register-bulk-nodes', method: 'POST', body: { networkNodes: [...BelayChain.networkNodes, BelayChain.nodeUrl]}, + headers: { 'Authorization': token }, json: true } return reqPromise(bulkRegisterOptions) }).then(data => { res.json({ message: 'Node registered with the network successfullly!'}) }) + }) + })