From 328d61be66acb0d0ebf727ce010bef246ec6135f Mon Sep 17 00:00:00 2001 From: Adrianus Cornet Date: Mon, 29 Jul 2019 11:23:42 +0200 Subject: [PATCH 1/4] Fix indentation --- auth.middleware.js | 12 ++++++------ sampleDate.js | 2 +- server.example1.js | 2 +- server.js | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/auth.middleware.js b/auth.middleware.js index 35dec2f..45cd44b 100644 --- a/auth.middleware.js +++ b/auth.middleware.js @@ -1,5 +1,5 @@ -const jwt = require('express-jwt'); -const jwksRsa = require('jwks-rsa'); +const jwt = require('express-jwt') +const jwksRsa = require('jwks-rsa') const authServerUrl = 'http://localhost:5000' @@ -18,18 +18,18 @@ const checkJwt = jwt({ const readProducts = (req, res, next) => { const user = req.user; - if(user['read:products'] === 'true') { + if (user['read:products'] === 'true') { return next() - } else{ + } else { return res.status(403).send('u dont have read access') } } const editProducts = (req, res, next) => { const user = req.user; - if(user['edit:products'] === 'true') { + if (user['edit:products'] === 'true') { return next() - } else{ + } else { return res.status(403).send('u dont have edit access') } } diff --git a/sampleDate.js b/sampleDate.js index bfd28b1..a9b813d 100644 --- a/sampleDate.js +++ b/sampleDate.js @@ -27,4 +27,4 @@ const sampleProducts = [ 'Zulu', ] -module.exports = {sampleProducts} \ No newline at end of file +module.exports = { sampleProducts } \ No newline at end of file diff --git a/server.example1.js b/server.example1.js index 60a6c69..b51629f 100644 --- a/server.example1.js +++ b/server.example1.js @@ -1,7 +1,7 @@ const express = require('express') const bodyParser = require('body-parser') const { promisify } = require('util') -const { auth, strategies, requiredScopes } = require('express-oauth2-bearer'); +const { auth, strategies, requiredScopes } = require('express-oauth2-bearer') const app = express() app.use(bodyParser.json()); diff --git a/server.js b/server.js index 60c72a2..95af087 100644 --- a/server.js +++ b/server.js @@ -1,7 +1,7 @@ const express = require('express') const bodyParser = require('body-parser') const { promisify } = require('util') -const { checkJwt, readProducts, editProducts } = require('./auth.middleware'); +const { checkJwt, readProducts, editProducts } = require('./auth.middleware') const { sampleProducts } = require('./sampleDate') const app = express() @@ -34,7 +34,7 @@ app.get('/sample', checkJwt, readProducts, (req, res) => { const limit = Number(req.query.limit) || 5 const offset = Number(req.query.offset) || 0 - const data = sampleProducts.slice(offset, offset+limit) + const data = sampleProducts.slice(offset, offset + limit) return res.status(200).send(data) }) From 1fa09af13dc91ea24840833b933ca5e26590b979 Mon Sep 17 00:00:00 2001 From: Adrianus Cornet Date: Mon, 29 Jul 2019 14:22:20 +0200 Subject: [PATCH 2/4] Get port from config file --- server.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 95af087..f5afe01 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ const bodyParser = require('body-parser') const { promisify } = require('util') const { checkJwt, readProducts, editProducts } = require('./auth.middleware') const { sampleProducts } = require('./sampleDate') +const { port } = require('./config') const app = express() app.use(bodyParser.json()) @@ -50,10 +51,10 @@ app.post('/sample', checkJwt, editProducts, (req, res) => { } }) -const startServer = async () => { - const port = process.env.SERVER_PORT || 3000 +const startServer = async (localPort) => { + const port = process.env.SERVER_PORT || localPort await promisify(app.listen).bind(app)(port) console.log(`Listening on port ${port}`) } -startServer() \ No newline at end of file +startServer(port) \ No newline at end of file From 72f928acbc76b3bfa026fbb1169a637b5155082b Mon Sep 17 00:00:00 2001 From: Adrianus Cornet Date: Mon, 29 Jul 2019 14:36:51 +0200 Subject: [PATCH 3/4] Use authorityUrl from config --- auth.middleware.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/auth.middleware.js b/auth.middleware.js index 45cd44b..4b50714 100644 --- a/auth.middleware.js +++ b/auth.middleware.js @@ -1,17 +1,16 @@ const jwt = require('express-jwt') const jwksRsa = require('jwks-rsa') - -const authServerUrl = 'http://localhost:5000' +const { authorityUrl } = require('./config') const checkJwt = jwt({ secret: jwksRsa.expressJwtSecret({ cache: false, rateLimit: true, jwksRequestsPerMinute: 5, - jwksUri: `http://172.16.31.64:5000/jwks`, + jwksUri: `${authorityUrl}/jwks`, }), audience: 'foo', - issuer: `${authServerUrl}`, + issuer: authorityUrl, algorithms: ['RS256'], }); From ff007486ad02ba1520909bd0be5a5aef42215b81 Mon Sep 17 00:00:00 2001 From: Adrianus Cornet Date: Mon, 29 Jul 2019 14:59:09 +0200 Subject: [PATCH 4/4] Clean up unnesesery asining --- server.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index f5afe01..fdba046 100644 --- a/server.js +++ b/server.js @@ -51,10 +51,9 @@ app.post('/sample', checkJwt, editProducts, (req, res) => { } }) -const startServer = async (localPort) => { - const port = process.env.SERVER_PORT || localPort +const startServer = async () => { await promisify(app.listen).bind(app)(port) console.log(`Listening on port ${port}`) } -startServer(port) \ No newline at end of file +startServer() \ No newline at end of file