From eb55534c48f0640e18abb03119fe9861cf9ef957 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 3 Nov 2015 00:02:32 -0800 Subject: [PATCH] add generateTotpUri() --- authenticator.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/authenticator.js b/authenticator.js index d17e75b..33618c9 100644 --- a/authenticator.js +++ b/authenticator.js @@ -57,3 +57,15 @@ function verifyGoogleAuthToken(key, token) { module.exports.generateKey = generateGoogleAuthKey; module.exports.generateToken = generateGoogleAuthToken; module.exports.verifyToken = verifyGoogleAuthToken; +module.exports.generateTotpUri = function (secret, accountName, issuer, algo, digits, period) { + // Full OTPAUTH URI spec as explained at + // https://github.com/google/google-authenticator/wiki/Key-Uri-Format + return 'otpauth://totp/' + + encodeURI(issuer || '') + ':' + encodeURI(accountName || '') + + '?secret=' + secret.replace(/[\s\.\_\-]+/g, '').toUpperCase() + + '&issuer=' + encodeURIComponent(issuer || '') + + '&algorithm=' + (algo || 'SHA1') + + '&digits=' + (digits || 6) + + '&period=' + (period || 30) + ; +};