Add MFA support

This commit is contained in:
garrettmills
2020-04-22 16:56:39 -05:00
parent d68d5141c8
commit e3ecfb0d37
30 changed files with 802 additions and 75 deletions

View File

@@ -0,0 +1,27 @@
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})`,
})
}
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

View File

@@ -14,6 +14,22 @@ class VueService extends Service {
}
}
}
auth_message(res, {message, next_destination, ...args}) {
const text = args.button_text || 'Continue'
return res.page('public:message', {
...this.data({
message,
actions: [
{
text,
action: 'redirect',
next: next_destination,
}
],
})
})
}
}
module.exports = exports = VueService