Guest User

Untitled

a guest
Mar 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <img src="...">
  2.  
  3. {
  4. "Version": "2012-10-17",
  5. "Statement": [
  6. {
  7. "Effect": "Allow",
  8. "Action": ["s3:ListBucket"],
  9. "Resource": ["arn:aws:s3:::<BUCKET-NAME>"],
  10. "Condition": {"StringLike": {"s3:prefix": ["cognito/<APPLICATION-NAME>/"]}}
  11. },
  12. {
  13. "Effect": "Allow",
  14. "Action": [
  15. "s3:GetObject",
  16. "s3:PutObject",
  17. "s3:DeleteObject"
  18. ],
  19. "Resource": [
  20. "arn:aws:s3:::<BUCKET-NAME>/cognito/<APPLICATION-NAME>/${cognito-identity.amazonaws.com:sub}",
  21. "arn:aws:s3:::<BUCKET-NAME>/cognito/<APPLICATION-NAME>/${cognito-identity.amazonaws.com:sub}/*"
  22. ]
  23. }
  24. ]
  25. }
  26.  
  27. var params = {Bucket: 'bucket', Key: 'key'};
  28. var url = s3.getSignedUrl('getObject', params);
  29.  
  30. login(credentials: UserCredentials, callback: (sm: StateMessage) => void, forcedChangePasswordCallback: () => void) {
  31. const username = credentials.login;
  32.  
  33. const authenticationData = {
  34. Username : username,
  35. Password : credentials.password
  36. };
  37. const authenticationDetails = new AuthenticationDetails(authenticationData);
  38.  
  39. this._createCognitoUser(username);
  40.  
  41. this.cognitoUser.authenticateUser(authenticationDetails, {
  42. onSuccess: (session: CognitoUserSession) => {
  43. // store token to use with all api request
  44. localStorage.setItem('idToken', session.getIdToken().getJwtToken());
  45.  
  46. // create credentials to access s3 correctly
  47. // AWS.config.region = '<region>';
  48.  
  49. // AWS.config.credentials = new CognitoIdentityCredentials({
  50. // IdentityPoolId : '...',
  51. // Logins : {
  52. // 'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>' : result.getIdToken().getJwtToken()
  53. // }
  54. // });
  55. // AWS.config.credentials.refresh((error) => {
  56. // if (error) {
  57. // console.error(error);
  58. // } else {
  59. // // Instantiate aws sdk service objects now that the credentials have been updated.
  60. // var s3 = new AWS.S3();
  61. // }
  62. // });
  63. },
  64. onFailure: (err) => {
  65. ...
  66. },
  67. });
  68. }
Add Comment
Please, Sign In to add comment