Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. function authenticateUserViaEmail() {
  2.  
  3. log("authenticateUserViaEmail called");
  4.  
  5. // Initialize the Amazon Cognito credentials provider
  6. AWS.config.region = 'us-east-1'; // Region
  7. AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  8. IdentityPoolId: identityPoolId,
  9. });
  10.  
  11. AWSCognito.config.region = 'us-east-1';
  12. AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
  13. IdentityPoolId: identityPoolId,
  14. });
  15.  
  16. var authenticationData = {
  17. Username : document.getElementById("email").value,
  18. Password : document.getElementById("password").value
  19. };
  20.  
  21. log("using: " + JSON.stringify(authenticationData));
  22.  
  23. var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
  24. var poolData = { UserPoolId : userPoolId,
  25. ClientId : clientId
  26. };
  27. var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
  28. var userData = {
  29. Username : document.getElementById("email").value,
  30. Pool : userPool
  31. };
  32. var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
  33.  
  34. log("About to call authenticateUser...");
  35.  
  36. cognitoUser.authenticateUser(authenticationDetails, {
  37. onSuccess: function (result) {
  38. log('Access token: ' + result.getAccessToken().getJwtToken());
  39. },
  40. onFailure: function(err) {
  41. log(err);
  42. console.error(err);
  43. },
  44. });
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement