Skip to content

Added MFA authenitcation support with prompt for confirmation code #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ function authenticate(callback) {
accessToken: result.getAccessToken().getJwtToken()
});
},
onFailure: function(err) {
onFailure: function(err) {``
console.log(err.message ? err.message : err);
},
newPasswordRequired: function() {
console.log("Given user needs to set a new password");
},
mfaRequired: function() {
console.log("MFA is not currently supported");
mfaRequired: function(authenticationDetails) {
promptConfirmationCode(function(confirmationCode, authenticator){
cognitoUser.sendMFACode(confirmationCode, authenticator);
}, this);
},
customChallenge: function() {
console.log("Custom challenge is not currently supported");
Expand Down Expand Up @@ -195,6 +197,21 @@ function makeRequest(userTokens) {
});
}

function promptConfirmationCode(callback, authenticator){
var readline = require('readline');

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question('Confirmation code (see SMS text message):', function(answer){
rl.close();
callback(answer, authenticator);
});

}

authenticate(function(tokens) {
getCredentials(tokens, makeRequest);
});
Loading