otplib API Documentation / otplib / generateURI
Function: generateURI()
generateURI(
options):string
Defined in: otplib/src/functional.ts:141
Generate an otpauth:// URI for QR code generation
This URI can be used to generate a QR code that can be scanned by Google Authenticator and other authenticator apps.
Parameters
options
URI generation options
algorithm?
counter?
number
digits?
issuer
string
label
string
period?
number
secret
string
strategy?
OTP strategy to use (default: 'totp')
Returns
string
otpauth:// URI string
Examples
ts
import { generateURI } from 'otplib';
const uri = generateURI({
issuer: 'ACME Co',
label: 'john@example.com',
secret: 'JBSWY3DPEHPK3PXP',
});
// Returns: 'otpauth://totp/ACME%20Co:john%40example.com?secret=...'ts
import { generateURI } from 'otplib';
const uri = generateURI({
strategy: 'hotp',
issuer: 'ACME Co',
label: 'john@example.com',
secret: 'JBSWY3DPEHPK3PXP',
counter: 5,
});
// Returns: 'otpauth://hotp/ACME%20Co:john%40example.com?secret=...&counter=5'