This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
| { | |
| "compilerOptions": { | |
| "outDir": "./built", | |
| "allowJs": true, | |
| "target": "ES2018", | |
| "moduleResolution": "node", | |
| "module": "commonjs" | |
| }, | |
| "include": [ | |
| "./src/**/*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AWS = require('aws-sdk'); | |
| const s3 = new AWS.S3({apiVersion: '2006-03-01'}); | |
| const uuidv4 = require('uuid/v4'); | |
| const bucketName = process.env.bucketName; | |
| const kmsKeyId = process.env.kmsKeyId; | |
| const MAX_FILE_SIZE = 5 * 1024 * 1024; | |
| const EXPIRATION = 900; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnInit, Injectable } from '@angular/core'; | |
| import { Router } from '@angular/router'; | |
| import { Observable } from 'rxjs'; | |
| import { HttpHeaders, HttpClient } from '@angular/common/http'; | |
| import { map } from 'rxjs/operators'; | |
| import { environment } from './../environments/environment'; | |
| const clientId = environment.clientId; | |
| const scope = 'https://www.googleapis.com/auth/youtube.readonly'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| variable "aws_region" { | |
| default = "us-east-1" | |
| } | |
| variable "vpc_cidr" { | |
| default = "10.0.0.0/16" | |
| } | |
| variable "webSubnetCidr" { | |
| default = "10.0.1.0/24" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let response = await login(email, password) | |
| const idToken = response.AuthenticationResult.IdToken | |
| const { identityId, credentials } = await getUserCredentials(idToken) | |
| const s3 = new AWS.S3({ credentials }) | |
| response = await s3.putObject({ | |
| Body: 'Hello world', | |
| Bucket: process.env.S3_BUCKET, | |
| Key: `${identityId}/foo.txt`, | |
| ContentType: 'text/plain' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function getUserCredentials(idToken) { | |
| const cognitoidentity = new AWS.CognitoIdentity() | |
| const providerName = `cognito-idp.${process.env.AWS_REGION}.amazonaws.com/${process.env.USER_POOL_ID}` | |
| let response = await cognitoidentity.getId({ | |
| IdentityPoolId: process.env.IDENTITY_POOL_ID, | |
| Logins: { | |
| [providerName]: idToken | |
| } | |
| }).promise() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Effect": "Allow", | |
| "Action": [ | |
| "s3:GetObject", | |
| "s3:PutObject", | |
| "s3:DeleteObject" | |
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Version": "2012-10-17", | |
| "Statement": [{ | |
| "Effect": "Allow", | |
| "Principal": {"Federated": "cognito-identity.amazonaws.com"}, | |
| "Action": "sts:AssumeRoleWithWebIdentity", | |
| "Condition": { | |
| "StringEquals": {"cognito-identity.amazonaws.com:aud": "<IDENTITY_POOL_ID>"}, | |
| "ForAnyValue:StringLike": {"cognito-identity.amazonaws.com:amr": "authenticated"} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function login(email, password) { | |
| try { | |
| const cognito = new AWS.CognitoIdentityServiceProvider() | |
| return await cognito.adminInitiateAuth({ | |
| AuthFlow: 'ADMIN_NO_SRP_AUTH', | |
| ClientId: process.env.CLIENT_ID, | |
| UserPoolId: process.env.USER_POOL_ID, | |
| AuthParameters: { | |
| USERNAME: email, | |
| PASSWORD: password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function signUp(email, password) { | |
| try { | |
| const cognito = new AWS.CognitoIdentityServiceProvider() | |
| await cognito.adminCreateUser({ | |
| UserPoolId: process.env.USER_POOL_ID, | |
| Username: email, | |
| MessageAction: 'SUPPRESS', | |
| TemporaryPassword: password, | |
| }).promise() |