Created
January 9, 2022 19:08
-
-
Save PatrickKalkman/36d526cebc05befe86bc840e390a7722 to your computer and use it in GitHub Desktop.
Enabling two factor authentication step 2
This file contains hidden or 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
userController.enableTwoFactorAuthStep2 = function (req, reply) { | |
tokenVerification.extractAndVerifyToken(req, (err, isValidJwtToken, email) => { | |
if (!err && isValidJwtToken) { | |
const user = db.getUser(email); | |
if (typeof user !== 'undefined') { | |
log.info(req.body); | |
const base32secret = req.body.base32; | |
const userToken = req.body.token; | |
const verified = speakeasy.totp.verify({ secret: base32secret, encoding: 'base32', token: userToken }); | |
if (verified) { | |
db.enableTwoFactorAuthentication(email); | |
reply.code(200).send({ validated: true }); | |
} else { | |
reply.code(200).send({ validated: false }); | |
} | |
} | |
} else { | |
reply.unauthorized(err); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment