Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const util = require("util");
const express = require('express');
const app = express();
const request = require('request')
const config = require('../config/config.js');
const barongAuth = require('node-auth-barong')
const barong_jwt_public_key = Buffer.from(global.gConfig.barong_jwt_public_key.trim(), 'base64').toString('utf-8')
const appPrivateKey = Buffer.from(global.gConfig.jwt.private_key.trim(), 'base64').toString('utf-8')

app.use(require('body-parser').json());

Expand All @@ -16,11 +18,39 @@ app.listen(global.gConfig.node_port || process.env.PORT, () => {
Valid JWT is decoded and session object is attached to the request object, which is passed to the next middleware.
*/

app.use(barongAuth({barongJwtPublicKey: barong_jwt_public_key }))
app.use(barongAuth.sessionVerifier({barongJwtPublicKey: barong_jwt_public_key }))

// When JWT is verified hello message is returned to the authorized user.
app.get('/api/v2/jwt/verify', function(req, res) {
console.log(`${req.method} ${req.originalUrl} ${util.inspect(req.body)}`)

res.send(`Hello, ${req.session.email}`)
})

app.post('/api/v2/deposit', function( req, res, next) {

if (req.session.role =! "admin") {
res.status(401);
res.send(`Deposit submittion is allowed only for admins`);
}

req.management = { payload: {
uid: req.session.uid,
currency: req.body.currency_id,
amount: req.body.amount
}
}
next();
}, barongAuth.managementSigner({privateKey: appPrivateKey}), function(req,res) {
request({
method: "POST",
uri: `${global.gConfig.peatio_url}/api/v2/management/deposits/new`,
json: true,
body: req.body
}, (err, result, body) => {
res.json(body)
if (err) {
return console.error(err);
}
});
})
1 change: 1 addition & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const environmentConfig = config[environment];
environmentConfig.barong_jwt_public_key =
process.env.BARONG_JWT_PUBLIC_KEY || defaultConfig.barong_jwt_public_key;
environmentConfig.barong_url = process.env.BARONG_URL || defaultConfig.barong_url;
environmentConfig.peatio_url = process.env.HOSTNAME || defaultConfig.peatio_url;
environmentConfig.jwt.expire_date = process.env.JWT_EXPIRE_DATE || 60;
environmentConfig.jwt.algorithm = process.env.JWT_ALGORITHM || 'RS256';
environmentConfig.jwt.private_key = process.env.JWT_PRIVATE_KEY || defaultConfig.jwt.private_key;
Expand Down
1 change: 1 addition & 0 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"node_port": 8081,
"json_indentation": 4,
"barong_url": "http://localhost:3000/api/v2/management/users/get",
"peatio_url": "http://localhost:8000",
"jwt": {
"expire_date": 60,
"algorithm": "RS256",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"express": "^4.16.3",
"jsonwebtoken": "^8.2.2",
"mongoose": "^5.6.6",
"node-auth-barong": "^1.0.0",
"@openware/node-auth-barong": "^1.1.0",
"request": "^2.81.0"
}
}