otpauth-uri-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

otpauth-uri-parser

A simple function for parsing otpauth:// URIs.

It uses the global URLSearchParams object, so this will only work in modern browsers and node >= 10 or with an appropriate polyfill.

This is based on the specs here so there might be some corner cases not covered.

Usage

It's pretty simple.

const parseURI = require('otpauth-uri-parser');

const parsed = parseURI('otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example');

console.log(parsed);

// Gives us:
{
    type: 'totp',
    label: { issuer: 'Example', account: 'alice@google.com' },
    query: { secret: 'JBSWY3DPEHPK3PXP', issuer: 'Example' }
}

Note: numeric query string parameters are not converted to numbers. So if the URI has digits=6 you will get { digits: '6' } in the query object and not { digits: 6 };

Contributing

If you encounter an otpauth:// URI that this fails to parse as expected please open an issue and ideally create a merge request with a failing test case.

Readme

Keywords

Package Sidebar

Install

npm i otpauth-uri-parser

Weekly Downloads

49

Version

1.0.2

License

MIT

Unpacked Size

8.93 kB

Total Files

8

Last publish

Collaborators

  • dominicp