diff options
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) + }) +} |
