mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-17 17:42:47 +08:00
https://linear.app/n8n/issue/ADO-947/sync-branch-with-master-and-fix-fe-e2e-tets --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
37 lines
730 B
TypeScript
37 lines
730 B
TypeScript
import OTPAuth from 'otpauth';
|
|
export class TOTPService {
|
|
generateSecret(): string {
|
|
return new OTPAuth.Secret()?.base32;
|
|
}
|
|
|
|
generateTOTPUri({
|
|
issuer = 'n8n',
|
|
secret,
|
|
label,
|
|
}: {
|
|
secret: string;
|
|
label: string;
|
|
issuer?: string;
|
|
}) {
|
|
return new OTPAuth.TOTP({
|
|
secret: OTPAuth.Secret.fromBase32(secret),
|
|
issuer,
|
|
label,
|
|
}).toString();
|
|
}
|
|
|
|
verifySecret({ secret, token, window = 1 }: { secret: string; token: string; window?: number }) {
|
|
return new OTPAuth.TOTP({
|
|
secret: OTPAuth.Secret.fromBase32(secret),
|
|
}).validate({ token, window }) === null
|
|
? false
|
|
: true;
|
|
}
|
|
|
|
generateTOTP(secret: string) {
|
|
return OTPAuth.TOTP.generate({
|
|
secret: OTPAuth.Secret.fromBase32(secret),
|
|
});
|
|
}
|
|
}
|