Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. AWSCognito.config.region = 'us-east-1'; //This is required to derive the endpoint
  2.  
  3. var poolData = { UserPoolId : 'us-east-1_TcoKGbf7n',
  4. ClientId : '4pe2usejqcdmhi0a25jp4b5sh3'
  5. };
  6. var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
  7.  
  8. var attributeList = [];
  9.  
  10. var dataEmail = {
  11. Name : 'email',
  12. Value : 'email@mydomain.com'
  13. };
  14. var dataPhoneNumber = {
  15. Name : 'phone_number',
  16. Value : '+15555555555'
  17. };
  18. var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
  19. var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);
  20.  
  21. attributeList.push(attributeEmail);
  22. attributeList.push(attributePhoneNumber);
  23.  
  24. userPool.signUp('username', 'password', attributeList, null, function(err, result){
  25. if (err) {
  26. alert(err);
  27. return;
  28. }
  29. cognitoUser = result.user;
  30. console.log('user name is ' + cognitoUser.getUsername());
  31. });
  32.  
  33. var authenticationData = {
  34. Username : 'username',
  35. Password : 'password'
  36. };
  37. var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
  38. var poolData = { UserPoolId : 'us-east-1_TcoKGbf7n',
  39. ClientId : '4pe2usejqcdmhi0a25jp4b5sh3'
  40. };
  41. var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
  42. var userData = {
  43. Username : 'username',
  44. Pool : userPool
  45. };
  46. var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
  47. cognitoUser.authenticateUser(authenticationDetails, {
  48. onSuccess: function (result) {
  49. console.log('access token + ' + result.getAccessToken().getJwtToken());
  50. /* Use the idToken for Logins Map when Federating User Pools with Cognito Identity or when passing through an Authorization Header to an API Gateway Authorizer */
  51. console.log('idToken + ' + result.idToken.jwtToken);
  52. },
  53. onFailure: function(err) {
  54. alert(err);
  55. },
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement