CoreID/app/services/MFA.service.js
garrettmills 97096f619f
All checks were successful
continuous-integration/drone/push Build is passing
Make UID case-insensitive
2020-10-18 23:27:23 -05:00

28 lines
764 B
JavaScript

const { Service } = require('flitter-di')
const speakeasy = require('speakeasy')
const qrcode = require('qrcode')
class MFAService extends Service {
static get services() {
return [...super.services, 'configs']
}
secret(user) {
return speakeasy.generateSecret({
length: this.configs.get('auth.mfa.secret_length') ?? 20,
name: `${this.configs.get('app.name')} (${user.uid.toLowerCase()})`,
})
}
async qr_code(secret) {
return new Promise((resolve, reject) => {
qrcode.toDataURL(secret.otpauth_url, (err, image_data) => {
if ( err ) reject(err)
else resolve(image_data)
})
})
}
}
module.exports = exports = MFAService