feat(2FA): add core library functions for TOTP, backup codes and rate limiting
This commit is contained in:
1 parent
8ce618c5a3
commit
683b956b9f
5 files changed
+148
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { generateSecret, generateURI, verify } from 'otplib';
|
||||
import qrcode from 'qrcode';
|
||||
|
||||
export function generateTotpSecret(): string {
|
||||
return generateSecret();
|
||||
}
|
||||
|
||||
export function generateOtpAuthUri(secret: string, userEmail: string): string {
|
||||
return generateURI({
|
||||
issuer: 'Umami',
|
||||
label: userEmail,
|
||||
secret,
|
||||
});
|
||||
}
|
||||
|
||||
export async function generateQrCodeDataUrl(otpAuthUri: string): Promise<string> {
|
||||
return qrcode.toDataURL(otpAuthUri, { errorCorrectionLevel: 'H' });
|
||||
}
|
||||
|
||||
export async function verifyTotp(token: string, secret: string): Promise<boolean> {
|
||||
const result = await verify({ secret, token });
|
||||
return result.valid;
|
||||
}
|
||||
Reference in new issue
Block a user