Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. require('dotenv').config();
  2.  
  3. // import {LoggedInCallback} from "../../MaximalAnalytics/src/models/cognito.service";
  4. var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
  5. var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;
  6. var CognitoUser = AmazonCognitoIdentity.CognitoUser;
  7. var CognitoUserAttribute = AmazonCognitoIdentity.CognitoUserAttribute;
  8. var CognitoUserSession = AmazonCognitoIdentity.CognitoUserSession;
  9. var AuthenticationDetails = AmazonCognitoIdentity.AuthenticationDetails;
  10.  
  11. var _POOL_DATA = {
  12. UserPoolId: process.env.IDENTITY_POOL_ID,
  13. ClientId: process.env.CLIENT_ID
  14. };
  15.  
  16. console.log("Before auth");
  17. function authenticate(username, password) {
  18.  
  19. var authenticationData = {
  20. Username : username,
  21. Password : password,
  22. };
  23. var authenticationDetails = new AuthenticationDetails(authenticationData);
  24.  
  25. var userData = {
  26. Username : username,
  27. Pool: _POOL_DATA
  28. };
  29. var cognitoUser = new CognitoUser(userData);
  30. cognitoUser.authenticateUser(authenticationDetails, {
  31. onSuccess: function (result) {
  32. console.log('access token + ' + result.getAccessToken().getJwtToken());
  33.  
  34. //POTENTIAL: Region needs to be set if not already set previously elsewhere.
  35. // AWS.config.region = '<region>';
  36. //
  37. // AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  38. // IdentityPoolId : '...', // your identity pool id here
  39. // Logins : {
  40. // // Change the key below according to the specific region your user pool is in.
  41. // 'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>' : result.getIdToken().getJwtToken()
  42. // }
  43. // });
  44.  
  45. // Instantiate aws sdk service objects now that the credentials have been updated.
  46. // example: var s3 = new AWS.S3();
  47.  
  48. },
  49.  
  50. onFailure: function(err) {
  51. alert(err);
  52. },
  53.  
  54. });
  55. // console.log('UserLoginService: starting the authentication');
  56. // let authenticationData = {
  57. // Username: username,
  58. // Password: password,
  59. // };
  60. // let authenticationDetails = new AuthenticationDetails(authenticationData);
  61. // console.log("authenticationDetails");
  62. // let userData = {
  63. // Username: username,
  64. // Pool: _POOL_DATA
  65. // };
  66. // console.log('UserLoginService: Params set...Authenticating the user');
  67. // let cognitoUser = new CognitoUser(userData);
  68. // console.log(authenticationDetails);
  69. // cognitoUser.authenticateUser(authenticationDetails, {
  70. // onSuccess: function (result) {
  71. // console.log("Auutheeeeenti");
  72. //
  73. // let logins = {};
  74. // logins['cognito-idp.' + process.env.REGION + '.amazonaws.com/' + process.env.COGNITO_POOL_NAME] = result.getIdToken().getJwtToken();
  75. // // callback.cognitoCallback(null, null);
  76. // console.log("DONE");
  77. // },
  78. // onFailure: function (err) {
  79. // console.log("ERRRRROR");
  80. // console.log(err);
  81. // // callback.cognitoCallback(err.message, null);
  82. // },
  83. // // newPasswordRequired: function (userAttributes, requiredAttributes) {
  84. // // callback.cognitoCallback(null, {
  85. // // changePassword: true,
  86. // // cognitoUser: cognitoUser,
  87. // // userAttributes: userAttributes
  88. // // });
  89. // // },
  90. // // mfaRequired: function (res, res2) {
  91. // //
  92. // // },
  93. // // customChallenge: function (res) {
  94. // //
  95. // // }
  96. // });
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement