add generateTotpUri()

This commit is contained in:
AJ ONeal 2015-11-03 00:02:32 -08:00
parent 461202f0ed
commit eb55534c48
1 changed files with 12 additions and 0 deletions

View File

@ -57,3 +57,15 @@ function verifyGoogleAuthToken(key, token) {
module.exports.generateKey = generateGoogleAuthKey; module.exports.generateKey = generateGoogleAuthKey;
module.exports.generateToken = generateGoogleAuthToken; module.exports.generateToken = generateGoogleAuthToken;
module.exports.verifyToken = verifyGoogleAuthToken; 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)
;
};