From 43b123b0508f70b2706ce379648c1435e9aeeecb Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 24 Jan 2019 20:24:46 -0800 Subject: email and phone verification and authy 2fa --- authy.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 authy.js (limited to 'authy.js') diff --git a/authy.js b/authy.js new file mode 100644 index 00000000..336cc2c5 --- /dev/null +++ b/authy.js @@ -0,0 +1,44 @@ +import { Client } from 'authy-client' +import config from './config' + +const authy = new Client({ key: config.authy.key }) + +export default async user => { + let { authyId } = user + + const res = await authy.createApprovalRequest({ + authyId: user.authyId, + details: { + visible: { + User: user.name, + } + }, + logos: [{ + res: 'default', + url: 'https://coinos.io/static/img/coinos.png' + }], + message: 'Login to CoinOS', + }, { + ttl: 120 + }); + + let counter = 0 + + return new Promise((resolve, reject) => { + let poll = setInterval(async () => { + counter++ + const r = await authy.getApprovalRequest({ id: res.approval_request.uuid }); + if (r.approval_request.status === 'approved') { + clearInterval(poll) + resolve(true) + } + + if (r.approval_request.status === 'denied') { + clearInterval(poll) + resolve(false) + } + + if (counter > 60) { clearInterval(poll); reject(false) } + }, 1000) + }) +} -- cgit v1.2.3