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,25 @@
const { Model } = require('flitter-orm')
const speakeasy = require('speakeasy')
class MFATokenModel extends Model {
static get services() {
return [...super.services, 'MFA']
}
static get schema() {
return {
secret: String,
otpauth_url: String,
}
}
verify(value) {
return speakeasy.totp.verify({
secret: this.secret,
encoding: 'base32',
token: value,
})
}
}
module.exports = exports = MFATokenModel

View File

@@ -2,6 +2,7 @@ const AuthUser = require('flitter-auth/model/User')
const LDAP = require('ldapjs')
const ActiveScope = require('../scopes/ActiveScope')
const MFAToken = require('./MFAToken.model')
/*
* Auth user model. This inherits fields and methods from the default
@@ -21,6 +22,8 @@ class User extends AuthUser {
email: String,
ldap_visible: {type: Boolean, default: true},
active: {type: Boolean, default: true},
mfa_token: MFAToken,
mfa_enabled: {type: Boolean, default: false},
}}
}