@@ -65,7 +65,19 @@ const generateSecret = ({ app, username, algorithm, digits, period }) => {
6565 secret
6666 } ) ;
6767 const url = totp . toString ( ) ;
68- return { secret : secret . base32 , url } ;
68+ const config = { mfa : secret . base32 } ;
69+ config . app = app ;
70+ config . url = url ;
71+ if ( algorithm !== 'SHA1' ) {
72+ config . mfaAlgorithm = algorithm ;
73+ }
74+ if ( digits != 6 ) {
75+ config . mfaDigits = digits ;
76+ }
77+ if ( period != 30 ) {
78+ config . mfaPeriod = period ;
79+ }
80+ return { config } ;
6981} ;
7082const showQR = text => {
7183 const QRCode = require ( 'qrcode' ) ;
@@ -77,7 +89,10 @@ const showQR = text => {
7789 } ) ;
7890} ;
7991
80- const showInstructions = ( { app, username, passwordCopied, secret, url, encrypt, config } ) => {
92+ const showInstructions = ( { app, username, passwordCopied, encrypt, config } ) => {
93+ const { secret, url} = config ;
94+ const mfaJSON = { ...config } ;
95+ delete mfaJSON . url ;
8196 let orderCounter = 0 ;
8297 const getOrder = ( ) => {
8398 orderCounter ++ ;
@@ -90,7 +105,7 @@ const showInstructions = ({ app, username, passwordCopied, secret, url, encrypt,
90105
91106 console . log (
92107 `\n${ getOrder ( ) } . Add the following settings for user "${ username } " ${ app ? `in app "${ app } " ` : '' } to the Parse Dashboard configuration.` +
93- `\n\n ${ JSON . stringify ( config ) } `
108+ `\n\n ${ JSON . stringify ( mfaJSON ) } `
94109 ) ;
95110
96111 if ( passwordCopied ) {
@@ -101,14 +116,14 @@ const showInstructions = ({ app, username, passwordCopied, secret, url, encrypt,
101116
102117 if ( secret ) {
103118 console . log (
104- `\n${ getOrder ( ) } . Open the authenticator app to scan the QR code above or enter this secret code:` +
105- `\n\n ${ secret } ` +
119+ `\n${ getOrder ( ) } . Open the authenticator app to scan the QR code above or enter this secret code:` +
120+ `\n\n ${ secret } ` +
106121 '\n\n If the secret code generates incorrect one-time passwords, try this alternative:' +
107- `\n\n ${ url } ` +
122+ `\n\n ${ url } ` +
108123 `\n\n${ getOrder ( ) } . Destroy any records of the QR code and the secret code to secure the account.`
109124 ) ;
110125 }
111-
126+
112127 if ( encrypt ) {
113128 console . log (
114129 `\n${ getOrder ( ) } . Make sure that "useEncryptedPasswords" is set to "true" in your dashboard configuration.` +
@@ -173,6 +188,7 @@ module.exports = {
173188 const salt = bcrypt . genSaltSync ( 10 ) ;
174189 data . pass = bcrypt . hashSync ( data . pass , salt ) ;
175190 }
191+ const config = { } ;
176192 if ( mfa ) {
177193 const { app } = await inquirer . prompt ( [
178194 {
@@ -182,18 +198,13 @@ module.exports = {
182198 }
183199 ] ) ;
184200 const { algorithm, digits, period } = await getAlgorithm ( ) ;
185- const { secret, url } = generateSecret ( { app, username, algorithm, digits, period } ) ;
186- data . mfa = secret ;
187- data . app = app ;
188- data . url = url ;
189- if ( algorithm !== 'SHA1' ) {
190- data . mfaAlgorithm = algorithm ;
191- }
192- showQR ( data . url ) ;
201+ const secret = generateSecret ( { app, username, algorithm, digits, period } ) ;
202+ Object . assign ( config , secret . config ) ;
203+ showQR ( secret . config . url ) ;
193204 }
194-
195- const config = { mfa : data . mfa , user : data . user , pass : data . pass } ;
196- showInstructions ( { app : data . app , username, passwordCopied : true , secret : data . mfa , url : data . url , encrypt, config } ) ;
205+ config . user = data . user ;
206+ config . pass = data . pass ;
207+ showInstructions ( { app : data . app , username, passwordCopied : true , encrypt, config } ) ;
197208 } ,
198209 async createMFA ( ) {
199210 console . log ( '' ) ;
@@ -212,14 +223,9 @@ module.exports = {
212223 ] ) ;
213224 const { algorithm, digits, period } = await getAlgorithm ( ) ;
214225
215- const { url, secret } = generateSecret ( { app, username, algorithm, digits, period } ) ;
216- showQR ( url ) ;
217-
226+ const { config } = generateSecret ( { app, username, algorithm, digits, period } ) ;
227+ showQR ( config . url ) ;
218228 // Compose config
219- const config = { mfa : secret } ;
220- if ( algorithm !== 'SHA1' ) {
221- config . mfaAlgorithm = algorithm ;
222- }
223- showInstructions ( { app, username, secret, url, config } ) ;
229+ showInstructions ( { app, username, config } ) ;
224230 }
225231} ;
0 commit comments