From ea40f02f0ca53e6f34d2546c418040b811740e5c Mon Sep 17 00:00:00 2001 From: "sid.gupta" Date: Sat, 30 Dec 2017 10:58:16 +0530 Subject: [PATCH 1/6] add aws amplify --- app-client/appsync-client/package.json | 2 + app-client/appsync-client/src/App.js | 10 +++- app-client/appsync-client/src/aws-exports.js | 5 +- app-client/appsync-client/yarn.lock | 63 ++++++++++++++++++++ 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/app-client/appsync-client/package.json b/app-client/appsync-client/package.json index a0216f04..042e134c 100644 --- a/app-client/appsync-client/package.json +++ b/app-client/appsync-client/package.json @@ -8,6 +8,8 @@ "apollo-client": "^2.0.2", "apollo-client-preset": "^1.0.2", "apollo-link": "^1.0.0", + "aws-amplify": "^0.1.30", + "aws-amplify-react": "^0.1.30", "aws-appsync": "^1.0.1", "aws-appsync-react": "^1.0.1", "aws-sdk": "^2.158.0", diff --git a/app-client/appsync-client/src/App.js b/app-client/appsync-client/src/App.js index f8dc4235..64880bb2 100644 --- a/app-client/appsync-client/src/App.js +++ b/app-client/appsync-client/src/App.js @@ -3,6 +3,8 @@ import UserList from './components/UserList'; import logo from './logo.svg'; import './App.css'; +import Amplify from 'aws-amplify'; +import { withAuthenticator } from 'aws-amplify-react'; import AWSAppSyncClient from 'aws-appsync'; import { Rehydrated } from 'aws-appsync-react'; import { AUTH_TYPE } from 'aws-appsync/lib/link/auth-link'; @@ -11,7 +13,6 @@ import * as AWS from 'aws-sdk'; import awsconfig from './aws-exports'; AWS.config.update({ - region: awsconfig.REGION, credentials: new AWS.Credentials({ accessKeyId: awsconfig.AWS_ACCESS_KEY_ID, secretAccessKey: awsconfig.AWS_SECRET_ACCESS_KEY, @@ -20,8 +21,11 @@ AWS.config.update({ const client = new AWSAppSyncClient({ url: process.env.REACT_APP_GRAPHQL_ENDPOINT, - region: 'us-east-1', - auth: { type: AUTH_TYPE.AWS_IAM, credentials: AWS.config.credentials }, + region: awsconfig.region, + auth: { + type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, + credentials: AWS.config.credentials, + }, }); class App extends Component { diff --git a/app-client/appsync-client/src/aws-exports.js b/app-client/appsync-client/src/aws-exports.js index 6b8381e3..20cf1a07 100644 --- a/app-client/appsync-client/src/aws-exports.js +++ b/app-client/appsync-client/src/aws-exports.js @@ -1,9 +1,6 @@ const config = { AWS_ACCESS_KEY_ID: '', AWS_SECRET_ACCESS_KEY: '', - HOST: 'xxxxxxx.dddpa.us-west-2.amazonaws.com', // Your hostname - REGION: 'us-west-2', //Your region - PATH: '/graphql', + REGION: 'us-east-1', }; -config.ENDPOINT = `https://${config.HOST}${config.PATH}`; export default config; diff --git a/app-client/appsync-client/yarn.lock b/app-client/appsync-client/yarn.lock index 3e3d9648..29d0cb7c 100644 --- a/app-client/appsync-client/yarn.lock +++ b/app-client/appsync-client/yarn.lock @@ -102,6 +102,13 @@ alphanum-sort@^1.0.1, alphanum-sort@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3" +amazon-cognito-identity-js@^1.19.0: + version "1.29.0" + resolved "https://registry.yarnpkg.com/amazon-cognito-identity-js/-/amazon-cognito-identity-js-1.29.0.tgz#bf1180a846b642e4aece3d970566d44e470c8162" + dependencies: + aws-sdk "^2.6.0" + js-cookie "^2.1.4" + amdefine@>=0.0.4: version "1.0.1" resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" @@ -412,6 +419,20 @@ autoprefixer@^6.3.1: postcss "^5.2.16" postcss-value-parser "^3.2.3" +aws-amplify-react@^0.1.30: + version "0.1.30" + resolved "https://registry.yarnpkg.com/aws-amplify-react/-/aws-amplify-react-0.1.30.tgz#03f75b614e1cd16549bbef17ad39f39c14b6e3a0" + +aws-amplify@^0.1.30: + version "0.1.30" + resolved "https://registry.yarnpkg.com/aws-amplify/-/aws-amplify-0.1.30.tgz#ee2c934cc58eb487c38ffe66853c2ad5b3eb3f02" + dependencies: + amazon-cognito-identity-js "^1.19.0" + aws-sdk "^2.101.0" + aws-sdk-mobile-analytics "^0.9.2" + axios "^0.17.0" + querystring-browser "^1.0.4" + aws-appsync-react@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/aws-appsync-react/-/aws-appsync-react-1.0.1.tgz#51ad70daf8fd9b477845d10c46a67f4ea189e122" @@ -436,6 +457,27 @@ aws-appsync@^1.0.0, aws-appsync@^1.0.1: redux-thunk "^2.2.0" url "^0.11.0" +aws-sdk-mobile-analytics@^0.9.2: + version "0.9.2" + resolved "https://registry.yarnpkg.com/aws-sdk-mobile-analytics/-/aws-sdk-mobile-analytics-0.9.2.tgz#b56a6e5206fc8c3975a19170b41536c53f6d5d91" + dependencies: + aws-sdk ">=2.2.37" + +aws-sdk@>=2.2.37, aws-sdk@^2.101.0, aws-sdk@^2.6.0: + version "2.176.0" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.176.0.tgz#2723c14e1c623ac45c5b890a3fc736eee8085f67" + dependencies: + buffer "4.9.1" + crypto-browserify "1.0.9" + events "^1.1.1" + jmespath "0.15.0" + querystring "0.2.0" + sax "1.2.1" + url "0.10.3" + uuid "3.1.0" + xml2js "0.4.17" + xmlbuilder "4.2.1" + aws-sdk@^2.139.0: version "2.158.0" resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.158.0.tgz#56ec1e78770822fbc38ae62fed0f54e7a147bdeb" @@ -474,6 +516,13 @@ aws4@^1.2.1: version "1.6.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" +axios@^0.17.0: + version "0.17.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.17.1.tgz#2d8e3e5d0bdbd7327f91bc814f5c57660f81824d" + dependencies: + follow-redirects "^1.2.5" + is-buffer "^1.1.5" + axobject-query@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-0.1.0.tgz#62f59dbc59c9f9242759ca349960e7a2fe3c36c0" @@ -2849,6 +2898,12 @@ flatten@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" +follow-redirects@^1.2.5: + version "1.2.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.6.tgz#4dcdc7e4ab3dd6765a97ff89c3b4c258117c79bf" + dependencies: + debug "^3.1.0" + for-in@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -4012,6 +4067,10 @@ js-base64@^2.1.9: version "2.3.2" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.3.2.tgz#a79a923666372b580f8e27f51845c6f7e8fbfbaf" +js-cookie@^2.1.4: + version "2.2.0" + resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.0.tgz#1b2c279a6eece380a12168b92485265b35b1effb" + js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" @@ -5476,6 +5535,10 @@ query-string@^4.1.0: object-assign "^4.1.0" strict-uri-encode "^1.0.0" +querystring-browser@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/querystring-browser/-/querystring-browser-1.0.4.tgz#f2e35881840a819bc7b1bf597faf0979e6622dc6" + querystring-es3@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" From 5151f2d807b3f29b0716c13e406566e1bd843d7b Mon Sep 17 00:00:00 2001 From: "sid.gupta" Date: Sat, 30 Dec 2017 11:40:55 +0530 Subject: [PATCH 2/6] add aws amplify --- app-client/appsync-client/src/App.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app-client/appsync-client/src/App.js b/app-client/appsync-client/src/App.js index 64880bb2..ce1a5864 100644 --- a/app-client/appsync-client/src/App.js +++ b/app-client/appsync-client/src/App.js @@ -12,11 +12,12 @@ import { ApolloProvider } from 'react-apollo'; import * as AWS from 'aws-sdk'; import awsconfig from './aws-exports'; -AWS.config.update({ - credentials: new AWS.Credentials({ - accessKeyId: awsconfig.AWS_ACCESS_KEY_ID, - secretAccessKey: awsconfig.AWS_SECRET_ACCESS_KEY, - }), +Amplify.configure({ + Auth: { + identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', //REQUIRED - Amazon Cognito Identity Pool ID + region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region + userPoolId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito User Pool ID + }, }); const client = new AWSAppSyncClient({ @@ -24,7 +25,6 @@ const client = new AWSAppSyncClient({ region: awsconfig.region, auth: { type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, - credentials: AWS.config.credentials, }, }); @@ -52,4 +52,4 @@ const WithProvider = () => ( ); -export default WithProvider; +export default withAuthenticator(WithProvider); From db85c223503e83885ce8b260cbfba0a43f74c84d Mon Sep 17 00:00:00 2001 From: "sid.gupta" Date: Fri, 5 Jan 2018 15:06:34 +0530 Subject: [PATCH 3/6] add auth flow --- app-client/appsync-client/src/App.js | 23 ++++++++++++-------- app-client/appsync-client/src/aws-exports.js | 6 ----- 2 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 app-client/appsync-client/src/aws-exports.js diff --git a/app-client/appsync-client/src/App.js b/app-client/appsync-client/src/App.js index ce1a5864..7a98c28a 100644 --- a/app-client/appsync-client/src/App.js +++ b/app-client/appsync-client/src/App.js @@ -3,28 +3,33 @@ import UserList from './components/UserList'; import logo from './logo.svg'; import './App.css'; -import Amplify from 'aws-amplify'; -import { withAuthenticator } from 'aws-amplify-react'; +import Amplify, { Auth } from 'aws-amplify'; +import { withAuthenticator } from 'aws-amplify-react/dist/Auth'; import AWSAppSyncClient from 'aws-appsync'; import { Rehydrated } from 'aws-appsync-react'; import { AUTH_TYPE } from 'aws-appsync/lib/link/auth-link'; import { ApolloProvider } from 'react-apollo'; -import * as AWS from 'aws-sdk'; -import awsconfig from './aws-exports'; Amplify.configure({ Auth: { - identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', //REQUIRED - Amazon Cognito Identity Pool ID - region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region - userPoolId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito User Pool ID + region: 'xx-xxxx-x', // REQUIRED - Amazon Cognito Region + userPoolId: 'xx-xxxx-x_xxxxxxxxx', //OPTIONAL - Amazon Cognito User Pool ID + userPoolWebClientId: 'xxxxx', //User Pool App Client ID }, }); +const getCreds = async () => { + return await Auth.currentSession() + .then(data => console.log(data)) + .catch(err => console.log(err)); +}; + const client = new AWSAppSyncClient({ url: process.env.REACT_APP_GRAPHQL_ENDPOINT, - region: awsconfig.region, + region: 'us-east-1', auth: { type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, + jwtToken: getCreds(), }, }); @@ -52,4 +57,4 @@ const WithProvider = () => ( ); -export default withAuthenticator(WithProvider); +export default withAuthenticator(WithProvider, { includeGreetings: true }); diff --git a/app-client/appsync-client/src/aws-exports.js b/app-client/appsync-client/src/aws-exports.js deleted file mode 100644 index 20cf1a07..00000000 --- a/app-client/appsync-client/src/aws-exports.js +++ /dev/null @@ -1,6 +0,0 @@ -const config = { - AWS_ACCESS_KEY_ID: '', - AWS_SECRET_ACCESS_KEY: '', - REGION: 'us-east-1', -}; -export default config; From 9efeea554dd607a72eb9e747efc230a22967bd79 Mon Sep 17 00:00:00 2001 From: "sid.gupta" Date: Fri, 5 Jan 2018 17:48:21 +0530 Subject: [PATCH 4/6] test next steps with aws amplify --- app-client/appsync-client/src/App.js | 12 +++++++----- config/security.env.local | 10 +++++++--- config/security.env.prod | 4 ++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app-client/appsync-client/src/App.js b/app-client/appsync-client/src/App.js index 7a98c28a..6fcf0109 100644 --- a/app-client/appsync-client/src/App.js +++ b/app-client/appsync-client/src/App.js @@ -12,21 +12,23 @@ import { ApolloProvider } from 'react-apollo'; Amplify.configure({ Auth: { - region: 'xx-xxxx-x', // REQUIRED - Amazon Cognito Region - userPoolId: 'xx-xxxx-x_xxxxxxxxx', //OPTIONAL - Amazon Cognito User Pool ID - userPoolWebClientId: 'xxxxx', //User Pool App Client ID + region: process.env.REACT_APP_AWS_AUTH_REGION, // REQUIRED - Amazon Cognito Region + userPoolId: process.env.REACT_APP_USER_POOL_ID, //OPTIONAL - Amazon Cognito User Pool ID + userPoolWebClientId: process.env.REACT_APP_CLIENT_APP_ID, //User Pool App Client ID }, }); const getCreds = async () => { return await Auth.currentSession() - .then(data => console.log(data)) + .then(data => { + return data.idToken.jwtToken; + }) .catch(err => console.log(err)); }; const client = new AWSAppSyncClient({ url: process.env.REACT_APP_GRAPHQL_ENDPOINT, - region: 'us-east-1', + region: process.env.REACT_APP_AWS_CLIENT_REGION, auth: { type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, jwtToken: getCreds(), diff --git a/config/security.env.local b/config/security.env.local index 14bdbc62..2854bd57 100644 --- a/config/security.env.local +++ b/config/security.env.local @@ -1,4 +1,8 @@ -REACT_APP_GRAPHQL_ENDPOINT=http://localhost:4000/graphql -REACT_APP_HANDLE=LeoDiCaprio +REACT_APP_GRAPHQL_ENDPOINT=https://exnijkhxynhxjfvrsr2lrsca4u.appsync-api.us-east-1.amazonaws.com/graphql +REACT_APP_HANDLE=sidg_sid REACT_APP_CONSUMER_KEY=N7vFfwCK4nM3DmzYZH4sTFKbS -REACT_APP_SECRET_KEY=HsrhKwC29Wtv6sJZEsU9UOtjnGpSn0a1PdjidvOQGKkNffJW7h \ No newline at end of file +REACT_APP_SECRET_KEY=HsrhKwC29Wtv6sJZEsU9UOtjnGpSn0a1PdjidvOQGKkNffJW7h +REACT_APP_AWS_AUTH_REGION=us-east-1 +REACT_APP_AWS_CLIENT_REGION=us-east-1 +REACT_APP_USER_POOL_ID=xxx +REACT_APP_CLIENT_APP_ID=xxx \ No newline at end of file diff --git a/config/security.env.prod b/config/security.env.prod index 24736913..93eaf691 100644 --- a/config/security.env.prod +++ b/config/security.env.prod @@ -4,3 +4,7 @@ REACT_APP_HANDLE=LeoDiCaprio REACT_APP_CONSUMER_KEY=N7vFfwCK4nM3DmzYZH4sTFKbS REACT_APP_SECRET_KEY=HsrhKwC29Wtv6sJZEsU9UOtjnGpSn0a1PdjidvOQGKkNffJW7h DATABASE_URL="" +REACT_APP_AWS_AUTH_REGION=us-east-1 +REACT_APP_AWS_CLIENT_REGION=us-east-1 +REACT_APP_USER_POOL_ID=xxx +REACT_APP_CLIENT_APP_ID=xxx From 7feb644530fab905b7c46b6a811a2c8d34aebb0b Mon Sep 17 00:00:00 2001 From: "sid.gupta" Date: Fri, 5 Jan 2018 17:51:50 +0530 Subject: [PATCH 5/6] remove creds --- config/security.env.local | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/security.env.local b/config/security.env.local index 2854bd57..03eaa793 100644 --- a/config/security.env.local +++ b/config/security.env.local @@ -1,5 +1,5 @@ -REACT_APP_GRAPHQL_ENDPOINT=https://exnijkhxynhxjfvrsr2lrsca4u.appsync-api.us-east-1.amazonaws.com/graphql -REACT_APP_HANDLE=sidg_sid +REACT_APP_GRAPHQL_ENDPOINT=http://localhost:4000/graphql +REACT_APP_HANDLE=LeoDiCaprio REACT_APP_CONSUMER_KEY=N7vFfwCK4nM3DmzYZH4sTFKbS REACT_APP_SECRET_KEY=HsrhKwC29Wtv6sJZEsU9UOtjnGpSn0a1PdjidvOQGKkNffJW7h REACT_APP_AWS_AUTH_REGION=us-east-1 From 59884bf50bd8251cc20d385ab2f1c72c052a1325 Mon Sep 17 00:00:00 2001 From: "sid.gupta" Date: Thu, 18 Jan 2018 20:08:39 -0800 Subject: [PATCH 6/6] remove idea files --- .idea/jsLibraryMappings.xml | 6 ------ .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/serverless-graphql.iml | 16 ---------------- .idea/vcs.xml | 6 ------ 5 files changed, 42 deletions(-) delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/serverless-graphql.iml delete mode 100644 .idea/vcs.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index b8387eb1..00000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 24eb271a..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 59d10cba..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/serverless-graphql.iml b/.idea/serverless-graphql.iml deleted file mode 100644 index ef55b413..00000000 --- a/.idea/serverless-graphql.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file