otplib API Documentation / @otplib/uri / parse
Function: parse()
parse(
uri):OTPAuthURI
Defined in: packages/uri/src/parse.ts:65
Parse an otpauth:// URI into its components
Parameters
uri
string
The otpauth:// URI to parse
Returns
Parsed URI components
Throws
If URI is invalid
Throws
If required parameters are missing
Throws
If parameter values are invalid
Example
ts
import { parse } from '@otplib/uri';
const uri = 'otpauth://totp/ACME:john@example.com?secret=JBSWY3DPEHPK3PXP&issuer=ACME';
const parsed = parse(uri);
// {
// type: 'totp',
// label: 'ACME:john@example.com',
// params: { secret: 'JBSWY3DPEHPK3PXP', issuer: 'ACME' }
// }