Guest User

Untitled

a guest
Dec 5th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. global.fetch = require ('node-fetch');
  2. var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
  3. var readline = require('readline');
  4.  
  5. const rl = readline.createInterface({
  6. input: process.stdin,
  7. output: process.stdout
  8. });
  9.  
  10. var confirmedUsername = 'XXXXXXXXXXXXX';
  11. var confirmedUserPassword = 'XXXXXXXX'
  12.  
  13. var authenticationData = {
  14. Username : confirmedUsername,
  15. Password : confirmedUserPassword,
  16. };
  17.  
  18. var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
  19.  
  20. var poolData = {
  21. UserPoolId : 'XXXXXXXXXXXXXXXXX',
  22. ClientId : 'XXXXXXXXXXXXXXX'
  23. };
  24.  
  25. var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
  26.  
  27. var userData = {
  28. Username : confirmedUsername,
  29. Pool : userPool
  30. };
  31.  
  32. var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
  33.  
  34. // code for simulating mfa
  35.  
  36. cognitoUser.authenticateUser(authenticationDetails, {
  37. onSuccess: function (result) {
  38. alert('authentication successful!')
  39. },
  40. onFailure: function(err) {
  41. alert(err);
  42. },
  43. mfaRequired: function(codeDeliveryDetails) {
  44. rl.question('Please enter the MFA code...\n', (answer) => {
  45. console.log('Thank you for your valuable feedback:', answer);
  46. cognitoUser.sendMFACode(answer, {
  47. onSuccess: (result) => {
  48. console.log(result);
  49. rl.close();
  50. }, onFailure: (err) => {
  51. console.log(err);
  52. rl.close();
  53. }
  54. });
  55. });
  56. }
  57. });
Add Comment
Please, Sign In to add comment