otplib API Documentation / otplib / functional / 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?
number
issuer
string
label
string
period?
number
secret
string
Base32-encoded secret key
Note: By default, strings are assumed to be Base32 encoded. If you have a raw string/passphrase, you must convert it to Uint8Array first.
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'