1
0
Fork 0

wip(backend): Added MFA support

This commit is contained in:
Joost De Cock 2022-11-17 20:41:21 +01:00
parent 36726dbdc3
commit a5ee0a0854
13 changed files with 380 additions and 14 deletions

View file

@ -0,0 +1,30 @@
import qrcode from 'qrcode'
import { authenticator } from '@otplib/preset-default'
const dark = '#AAAAAA'
const light = '#EEEEEE'
/*
* Exporting this closure that makes sure we have access to the
* instantiated config
*/
export const mfa = ({ service }) => ({
mfa: {
enroll: async (user) => {
const secret = authenticator.generateSecret()
const otpauth = authenticator.keyuri(user, service, secret)
let svg
try {
svg = await qrcode.toString(otpauth, {
type: 'svg',
color: { dark, light },
})
} catch (err) {
console.log(err)
}
svg = svg.replace(dark, 'currentColor').replace(light, 'none')
return { secret, otpauth, qrcode: svg }
},
verify: (token, secret) => authenticator.check(token, secret),
},
})