Phase1
This commit is contained in:
21
packages/auth/src/totp.ts
Normal file
21
packages/auth/src/totp.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { authenticator } from 'otplib';
|
||||
|
||||
export function generateTotpSecret(): string {
|
||||
return authenticator.generateSecret();
|
||||
}
|
||||
|
||||
export function verifyTotpCode(secret: string, code: string): boolean {
|
||||
try {
|
||||
return authenticator.verify({ token: code.replace(/\s+/gu, ''), secret });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function buildOtpAuthUrl(
|
||||
issuer: string,
|
||||
accountName: string,
|
||||
secret: string,
|
||||
): string {
|
||||
return authenticator.keyuri(accountName, issuer, secret);
|
||||
}
|
||||
Reference in New Issue
Block a user