Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global.fetch = require ('node-fetch');
- var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
- var readline = require('readline');
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- var confirmedUsername = 'XXXXXXXXXXXXX';
- var confirmedUserPassword = 'XXXXXXXX'
- var authenticationData = {
- Username : confirmedUsername,
- Password : confirmedUserPassword,
- };
- var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
- var poolData = {
- UserPoolId : 'XXXXXXXXXXXXXXXXX',
- ClientId : 'XXXXXXXXXXXXXXX'
- };
- var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
- var userData = {
- Username : confirmedUsername,
- Pool : userPool
- };
- var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
- // code for simulating mfa
- cognitoUser.authenticateUser(authenticationDetails, {
- onSuccess: function (result) {
- alert('authentication successful!')
- },
- onFailure: function(err) {
- alert(err);
- },
- mfaRequired: function(codeDeliveryDetails) {
- rl.question('Please enter the MFA code...\n', (answer) => {
- console.log('Thank you for your valuable feedback:', answer);
- cognitoUser.sendMFACode(answer, {
- onSuccess: (result) => {
- console.log(result);
- rl.close();
- }, onFailure: (err) => {
- console.log(err);
- rl.close();
- }
- });
- });
- }
- });
Add Comment
Please, Sign In to add comment