add generateTotpUri()

This commit is contained in:
AJ ONeal 2015-11-03 00:02:32 -08:00
vecāks 461202f0ed
revīzija eb55534c48
1 mainīti faili ar 12 papildinājumiem un 0 dzēšanām

Parādīt failu

@ -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)
;
};