Guest User

Untitled

a guest
Oct 29th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. exports.authCognitoUser = function(theUserPoolID, theClientID, userName, userPassword) {
  2.  
  3. var authenticationData = {
  4. Username : userName,
  5. Password : userPassword
  6. };
  7.  
  8. var authenticationDetails = new AWSCognito.AuthenticationDetails(authenticationData);
  9.  
  10. var poolData = { UserPoolId : theUserPoolID,
  11. ClientId : theClientID
  12. };
  13. var userPool = new AWSCognito.CognitoUserPool(poolData);
  14.  
  15. var userData = {
  16. Username : userName,
  17. Pool : userPool
  18. };
  19.  
  20. console.log('authentication details: ',authenticationDetails);
  21.  
  22. var cognitoUser = new AWSCognito.CognitoUser(userData);
  23.  
  24. cognitoUser.authenticateUser(authenticationDetails, {
  25. onSuccess: function (result) {
  26. console.log('access token + ' + result.getAccessToken().getJwtToken());
  27. console.log('id token + ' + result.getIdToken().getJwtToken());
  28. console.log('refresh token + ' + result.getRefreshToken().getToken());
  29. return result;
  30. },
  31. onFailure: function(err) {
  32. console.log(err.message || JSON.stringify(err));
  33. return err;
  34. },
  35.  
  36. });
  37.  
  38. }
  39.  
  40. authentication details: AuthenticationDetails {
  41. validationData: {},
  42. authParameters: {},
  43. username: 'thesmarterstuff',
  44. password: 'passW0rd!’ }
Add Comment
Please, Sign In to add comment