26 lines
526 B
JavaScript
26 lines
526 B
JavaScript
|
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
|