Created
May 4, 2018 13:17
-
-
Save madhavanmalolan/72189767154f2c674b83631e60a8e266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var axios = require('axios'); | |
var crypto = require('crypto'); | |
var cryptico = require('cryptico'); | |
var BASE_URL = "https://dauth.co/"; | |
router.get("/demo", function(req, res, next){ | |
var username = req.query.username; | |
var code = req.query.code; | |
var hashcode = req.query.hashcode; | |
var urlGetter = BASE_URL + "utils/url?username="+username; | |
var keyGetter = BASE_URL + "utils/key?username="+username; | |
axios.get(urlGetter).then(function(aUrl){ | |
axios.get(keyGetter).then(function(aKey){ | |
var tokenRaw = crypto.createHash('sha256').update(Math.random().toString()).digest('base64').substr(0,10); | |
var encrypted = cryptico.encrypt(tokenRaw, aKey.data, "").cipher; | |
axios.post(aUrl.data+"?action=verify", {username:username,code:code, hashcode:hashcode, cipher: encrypted}).then(function(decrypted){ | |
res.send(decrypted); | |
}); | |
}).catch(function(error){ | |
res.status(500).send({message:error}); | |
}); | |
}).catch(function(error){ | |
res.status(500).send({message:error}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment