/** * This router handles things related to the web browser experience... */ // This is the mock data we working with... module.exports = function (options) { const config = require('config'); var QRCode = require('qrcode'); var express = options.express; const db = options.db; const hdAuthUtil = options.hdAuthUtil; var router = express.Router(); router.route('/sign') .post(function(request, response, next) { // Verify challenge db.Challenge.findByPk(request.body.id, { where: { response: null } }).then(challenge => { if (challenge) { challenge.response = { signature: request.body.signature }; if(hdAuthUtil.verifyHDAuthChallengeResponse(challenge)) { challenge.save().then(() => { response.json({ "message": "challenge response accepted" }) }); } else { response.status(401); // user failed challenge // TODO: Validate input // TODO: Createa new challenge console.error("User failed to authenticate"); // Create new challenge and try again... } } else { response.status(500); } }); }) // TODO: add other endpoints return router; };