otpauth-uri-parser
v1.0.2
Published
A simple function to parse otpauth:// URIs
Downloads
903
Readme
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:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example');
console.log(parsed);
// Gives us:
{
type: 'totp',
label: { issuer: 'Example', account: '[email protected]' },
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.