Advertisement
Guest User

Untitled

a guest
May 12th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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.  
  23. onSuccess: function (result) {
  24.  
  25. AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  26. IdentityPoolId : config.IdentityPoolId, // your identity pool id here
  27. Logins : {
  28. ['cognito-idp.' + config.region + '.amazonaws.com/' + config.UserPoolId] : result.getIdToken().getJwtToken()
  29. }
  30. });
  31.  
  32. // var additionalParams = {
  33. // headers: {
  34. // "Access-Control-Allow-Origin": "*",
  35. // "Access-Control-Allow-Methods": "GET,OPTIONS",
  36. // // "Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token",
  37. // "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
  38. //
  39. // },
  40. // };
  41.  
  42. AWS.config.credentials.get(function() {
  43. console.log('AWS.config', AWS.config.credentials);
  44. var apigClient = window.apigClientFactory.newClient({
  45. accessKey: AWS.config.credentials.accessKeyId,
  46. secretKey: AWS.config.credentials.secretAccessKey,
  47. sessionToken: AWS.config.sessionToken,
  48. region: config.region
  49. });
  50. apigClient.identityiamGet({}, '', {});
  51. });
  52.  
  53. },
  54. onFailure: function(err) {
  55. alert(err);
  56. },
  57. });
  58. };
  59. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement