Advertisement
Guest User

Untitled

a guest
May 11th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. ```
  2. const login = () => {
  3.  
  4. let Username = 'reacttest';
  5. let Password = 'reacttest';
  6.  
  7. let authenticationDetails = new AuthenticationDetails({
  8. Username,
  9. Password
  10. });
  11.  
  12. const { UserPoolId, ClientId } = config;
  13. var poolData = { UserPoolId, ClientId };
  14. var userPool = new CognitoUserPool(poolData);
  15. var userData = {
  16. Username : 'reacttest',
  17. Pool : userPool
  18. };
  19. var cognitoUser = new CognitoUser(userData);
  20.  
  21. cognitoUser.authenticateUser(authenticationDetails, {
  22. onSuccess: function (result) {
  23.  
  24. AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  25. IdentityPoolId : config.IdentityPoolId, // your identity pool id here
  26. Logins : {
  27. ['cognito-idp.' + config.region + '.amazonaws.com/' + config.UserPoolId] : result.getIdToken().getJwtToken()
  28. }
  29. });
  30.  
  31. AWS.config.credentials.get(function() {
  32. console.log('AWS.config', AWS.config.credentials);
  33. var apigClient = window.apigClientFactory.newClient({
  34. accessKey: AWS.config.credentials.accessKeyId,
  35. secretKey: AWS.config.credentials.secretAccessKey,
  36. sessionToken: AWS.config.sessionToken, //OPTIONAL: If you are using temporary credentials you must include the session token
  37. region: config.region // OPTIONAL: The region where the API is deployed, by default this parameter is set to us-east-1
  38. });
  39. // apigClient.identityGet({}, {}, {});
  40. apigClient.identityGet({}, {}, {});
  41. });
  42. },
  43. onFailure: function(err) {
  44. alert(err);
  45. },
  46. });
  47. };
  48. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement