UNPKG

@dax-crafta/auth

Version:

A powerful, flexible, and secure authentication plugin for the Crafta framework. Supports JWT, social login, 2FA, RBAC, audit logging, and enterprise-grade security features.

38 lines (32 loc) 786 B
const speakeasy = require('speakeasy'); const qrcode = require('qrcode'); class MFAService { async generateSecret(label, issuer = 'App') { const secret = speakeasy.generateSecret({ length: 20, name: label, issuer }); const qrCodeUrl = await qrcode.toDataURL(secret.otpauth_url); return { secret: secret.base32, qrCode: qrCodeUrl }; } verifyToken(token, secret) { return speakeasy.totp.verify({ secret, encoding: 'base32', token, window: 1 }); } generateBackupCodes() { const codes = []; for (let i = 0; i < 10; i++) { codes.push(speakeasy.generateSecret({ length: 10 }).base32); } return codes; } } module.exports = MFAService;