najimCseJu

PostmanAutomationAwsCognito

Apr 4th, 2023
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. # Endpoint:
  2. https://cognito-idp.ap-southeast-2.amazonaws.com/
  3.  
  4. # Curl Command:
  5. curl --location 'https://cognito-idp.ap-southeast-2.amazonaws.com/' \
  6. --header 'Content-Type: application/x-amz-json-1.1' \
  7. --header 'x-amz-target: AWSCognitoIdentityProviderService.InitiateAuth' \
  8. --data-raw '{
  9. "AuthFlow": "USER_PASSWORD_AUTH",
  10. "ClientId": "{{clientId}}",
  11. "AuthParameters": {
  12. "USERNAME": "{{email}}",
  13. "PASSWORD":"{{password}}",
  14. "SECRET_HASH": "{{secretHash}}"
  15. }
  16. }'
  17.  
  18. # Pre-request Script:
  19. const clientSecret = pm.environment.get("clientSecret")
  20. const clientId = pm.environment.get("clientId")
  21. const email = pm.environment.get("email")
  22.  
  23. pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js", (error, response) => {
  24. if (error || response.code !== 200) {
  25. pm.expect.fail('Could not load external library');
  26. }
  27. eval(response.text());
  28. const CryptoJS = require('crypto-js');
  29. const digest = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(email + clientId, clientSecret));
  30. pm.environment.set("secretHash",digest.toString())
  31. });
  32.  
  33. # Test:
  34. const responseJson = pm.response.json();
  35. console.log("response",responseJson)
  36. pm.environment.set("token",responseJson['AuthenticationResult']['AccessToken'])
  37.  
Add Comment
Please, Sign In to add comment