diff options
| author | Adam Soltys <[email protected]> | 2019-01-24 20:24:46 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2019-02-05 20:53:45 -0800 |
| commit | 43b123b0508f70b2706ce379648c1435e9aeeecb (patch) | |
| tree | 7836f63c8cf0037e21790695caee57fec2b87968 /authy.js | |
| parent | 3fe77ca010a1946b77fdb5288dd7a628f80cadeb (diff) | |
| download | coinos-server-43b123b0508f70b2706ce379648c1435e9aeeecb.tar.gz coinos-server-43b123b0508f70b2706ce379648c1435e9aeeecb.zip | |
email and phone verification and authy 2fa
Diffstat (limited to 'authy.js')
| -rw-r--r-- | authy.js | 44 |
1 files changed, 44 insertions, 0 deletions
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) + }) +} |
