├── 10-TOTP-MFA ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── RandomNumber.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── Attributes.js │ │ ├── ChangeEmail.js │ │ ├── ForgotPassword.js │ │ ├── Accounts.js │ │ └── MFA.js │ └── App.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── lambda │ ├── disable-mfa │ │ ├── package.json │ │ └── index.js │ ├── validate-mfa │ │ ├── package.json │ │ └── index.js │ ├── get-qr-code │ │ ├── package.json │ │ └── index.js │ └── create-api-key │ │ ├── package.json │ │ └── index.js └── package.json ├── 9-API-Keys ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── RandomNumber.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── Attributes.js │ │ ├── ChangeEmail.js │ │ ├── ForgotPassword.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── lambda │ ├── package.json │ └── index.js └── package.json ├── 11-Delete-Users ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── RandomNumber.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── Attributes.js │ │ ├── ChangeEmail.js │ │ ├── ForgotPassword.js │ │ ├── Accounts.js │ │ └── MFA.js │ └── App.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── lambda │ ├── delete-user │ │ ├── config.json │ │ ├── package.json │ │ └── index.js │ ├── disable-mfa │ │ ├── package.json │ │ └── index.js │ ├── validate-mfa │ │ ├── package.json │ │ └── index.js │ ├── get-qr-code │ │ ├── package.json │ │ └── index.js │ └── create-api-key │ │ ├── package.json │ │ └── index.js └── package.json ├── 2-Cognito-Signin ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Signup.js │ │ └── Login.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 1-Cognito-Signup ├── src │ ├── index.css │ ├── index.js │ └── App.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 3-Cognito-Sessions-Logout ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Status.js │ │ ├── Signup.js │ │ ├── Login.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 4-Cognito-Change-Password ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Settings.js │ │ ├── Status.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 5-Cognito-Change-Email ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── ChangeEmail.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 6-Cognito-Forgot-Password ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── ChangeEmail.js │ │ ├── ForgotPassword.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 7-Cognito-User-Attributes ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── Attributes.js │ │ ├── ChangeEmail.js │ │ ├── ForgotPassword.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── 8-API-Gateway-Authorization ├── src │ ├── App.css │ ├── index.css │ ├── index.js │ ├── UserPool.js │ ├── App.js │ └── components │ │ ├── Status.js │ │ ├── Settings.js │ │ ├── RandomNumber.js │ │ ├── Signup.js │ │ ├── Login.js │ │ ├── ChangePassword.js │ │ ├── Attributes.js │ │ ├── ChangeEmail.js │ │ ├── ForgotPassword.js │ │ └── Accounts.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html └── package.json ├── README.md └── .gitignore /10-TOTP-MFA/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /9-API-Keys/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /11-Delete-Users/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-Cognito-Signin/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /9-API-Keys/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1-Cognito-Signup/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /11-Delete-Users/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-Cognito-Signin/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /9-API-Keys/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /10-TOTP-MFA/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /11-Delete-Users/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /1-Cognito-Signup/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /2-Cognito-Signin/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/delete-user/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "sub": "57295370-aaf7-46a5-8c8f-6b49702921f6" 3 | } 4 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /9-API-Keys/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/9-API-Keys/public/favicon.ico -------------------------------------------------------------------------------- /9-API-Keys/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/9-API-Keys/public/logo192.png -------------------------------------------------------------------------------- /9-API-Keys/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/9-API-Keys/public/logo512.png -------------------------------------------------------------------------------- /10-TOTP-MFA/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/10-TOTP-MFA/public/favicon.ico -------------------------------------------------------------------------------- /10-TOTP-MFA/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/10-TOTP-MFA/public/logo192.png -------------------------------------------------------------------------------- /10-TOTP-MFA/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/10-TOTP-MFA/public/logo512.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | If you need help with anything then feel free to ask in the Worn Off Keys Discord server: 2 | 3 | https://wornoffkeys.com/discord 4 | -------------------------------------------------------------------------------- /11-Delete-Users/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/11-Delete-Users/public/favicon.ico -------------------------------------------------------------------------------- /11-Delete-Users/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/11-Delete-Users/public/logo192.png -------------------------------------------------------------------------------- /11-Delete-Users/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/11-Delete-Users/public/logo512.png -------------------------------------------------------------------------------- /1-Cognito-Signup/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/1-Cognito-Signup/public/favicon.ico -------------------------------------------------------------------------------- /1-Cognito-Signup/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/1-Cognito-Signup/public/logo192.png -------------------------------------------------------------------------------- /1-Cognito-Signup/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/1-Cognito-Signup/public/logo512.png -------------------------------------------------------------------------------- /2-Cognito-Signin/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/2-Cognito-Signin/public/favicon.ico -------------------------------------------------------------------------------- /2-Cognito-Signin/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/2-Cognito-Signin/public/logo192.png -------------------------------------------------------------------------------- /2-Cognito-Signin/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/2-Cognito-Signin/public/logo512.png -------------------------------------------------------------------------------- /5-Cognito-Change-Email/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/5-Cognito-Change-Email/public/favicon.ico -------------------------------------------------------------------------------- /5-Cognito-Change-Email/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/5-Cognito-Change-Email/public/logo192.png -------------------------------------------------------------------------------- /5-Cognito-Change-Email/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/5-Cognito-Change-Email/public/logo512.png -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/3-Cognito-Sessions-Logout/public/favicon.ico -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/3-Cognito-Sessions-Logout/public/logo192.png -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/3-Cognito-Sessions-Logout/public/logo512.png -------------------------------------------------------------------------------- /4-Cognito-Change-Password/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/4-Cognito-Change-Password/public/favicon.ico -------------------------------------------------------------------------------- /4-Cognito-Change-Password/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/4-Cognito-Change-Password/public/logo192.png -------------------------------------------------------------------------------- /4-Cognito-Change-Password/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/4-Cognito-Change-Password/public/logo512.png -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/6-Cognito-Forgot-Password/public/favicon.ico -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/6-Cognito-Forgot-Password/public/logo192.png -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/6-Cognito-Forgot-Password/public/logo512.png -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/7-Cognito-User-Attributes/public/favicon.ico -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/7-Cognito-User-Attributes/public/logo192.png -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/7-Cognito-User-Attributes/public/logo512.png -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/8-API-Gateway-Authorization/public/favicon.ico -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/8-API-Gateway-Authorization/public/logo192.png -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexzanderFlores/Worn-Off-Keys-Cognito-Tutorials/HEAD/8-API-Gateway-Authorization/public/logo512.png -------------------------------------------------------------------------------- /1-Cognito-Signup/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); -------------------------------------------------------------------------------- /10-TOTP-MFA/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /9-API-Keys/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /11-Delete-Users/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /2-Cognito-Signin/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | -------------------------------------------------------------------------------- /9-API-Keys/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /10-TOTP-MFA/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /11-Delete-Users/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /2-Cognito-Signin/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/UserPool.js: -------------------------------------------------------------------------------- 1 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 2 | 3 | const poolData = { 4 | UserPoolId: 'us-east-1_8WMsl8AMg', 5 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 6 | }; 7 | 8 | export default new CognitoUserPool(poolData); -------------------------------------------------------------------------------- /2-Cognito-Signin/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Signup from "./components/Signup"; 3 | import Login from "./components/Login"; 4 | 5 | export default () => { 6 | return ( 7 |
8 | 9 | 10 |
11 | ); 12 | }; 13 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/disable-mfa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "disable-mfa", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/validate-mfa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-mfa", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/delete-user/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "delete-user", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/disable-mfa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "disable-mfa", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/validate-mfa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-mfa", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/get-qr-code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get-qr-code", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "qrcode": "^1.4.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/get-qr-code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "get-qr-code", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "qrcode": "^1.4.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Account } from './components/Accounts'; 3 | import Signup from './components/Signup'; 4 | import Login from './components/Login'; 5 | import Status from './components/Status'; 6 | 7 | export default () => { 8 | return ( 9 | 10 | 11 | 12 | 13 | 14 | ); 15 | }; -------------------------------------------------------------------------------- /9-API-Keys/lambda/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lambda", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node -e \"(async () => console.log(await require('./index').handler({'sub':'4e3297c7-495d-486b-9556-3ec79870ec41'})))();\"" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "aws-sdk": "^2.699.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/create-api-key/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lambda", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node -e \"(async () => console.log(await require('./index').handler({'sub':'4e3297c7-495d-486b-9556-3ec79870ec41'})))();\"" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "aws-sdk": "^2.699.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/create-api-key/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lambda", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node -e \"(async () => console.log(await require('./index').handler({'sub':'4e3297c7-495d-486b-9556-3ec79870ec41'})))();\"" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "aws-sdk": "^2.699.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Account } from "./components/Accounts"; 3 | import Signup from "./components/Signup"; 4 | import Login from "./components/Login"; 5 | import Status from "./components/Status"; 6 | import Settings from "./components/Settings"; 7 | 8 | export default () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | 16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Account } from "./components/Accounts"; 3 | import Signup from "./components/Signup"; 4 | import Login from "./components/Login"; 5 | import Status from "./components/Status"; 6 | import Settings from "./components/Settings"; 7 | 8 | export default () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | 16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Account } from "./components/Accounts"; 3 | import Signup from "./components/Signup"; 4 | import Login from "./components/Login"; 5 | import ForgotPassword from "./components/ForgotPassword"; 6 | import Status from "./components/Status"; 7 | import Settings from "./components/Settings"; 8 | 9 | export default () => { 10 | return ( 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ); 19 | }; 20 | -------------------------------------------------------------------------------- /10-TOTP-MFA/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /9-API-Keys/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /1-Cognito-Signup/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /11-Delete-Users/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /2-Cognito-Signin/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Account } from "./components/Accounts"; 3 | import Signup from "./components/Signup"; 4 | import Login from "./components/Login"; 5 | import ForgotPassword from "./components/ForgotPassword"; 6 | import Status from "./components/Status"; 7 | import Settings from "./components/Settings"; 8 | import Attributes from "./components/Attributes"; 9 | 10 | export default () => { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ); 21 | }; 22 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/validate-mfa/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | 3 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 4 | 5 | const validateMFA = async (UserCode, AccessToken) => 6 | await new Promise((resolve, reject) => { 7 | const params = { 8 | AccessToken, 9 | UserCode, 10 | } 11 | 12 | cognito.verifySoftwareToken(params, (err, result) => { 13 | if (err) reject(err) 14 | else resolve(result) 15 | }) 16 | }) 17 | 18 | const main = async (event) => { 19 | console.log('Event:', event) 20 | return validateMFA(event.userCode, event.accessToken) 21 | } 22 | 23 | exports.handler = main 24 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/validate-mfa/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | 3 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 4 | 5 | const validateMFA = async (UserCode, AccessToken) => 6 | await new Promise((resolve, reject) => { 7 | const params = { 8 | AccessToken, 9 | UserCode, 10 | } 11 | 12 | cognito.verifySoftwareToken(params, (err, result) => { 13 | if (err) reject(err) 14 | else resolve(result) 15 | }) 16 | }) 17 | 18 | const main = async (event) => { 19 | console.log('Event:', event) 20 | return validateMFA(event.userCode, event.accessToken) 21 | } 22 | 23 | exports.handler = main 24 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | 5 | export default () => { 6 | const [loggedIn, setLoggedIn] = useState(false); 7 | 8 | const { getSession } = useContext(AccountContext); 9 | 10 | useEffect(() => { 11 | getSession().then(() => { 12 | setLoggedIn(true); 13 | }); 14 | }, []); 15 | 16 | return ( 17 |
18 | {loggedIn && ( 19 | <> 20 |

Settings

21 | 22 | 23 | 24 | )} 25 |
26 | ); 27 | }; 28 | -------------------------------------------------------------------------------- /9-API-Keys/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Account } from './components/Accounts' 3 | import Signup from './components/Signup' 4 | import Login from './components/Login' 5 | import ForgotPassword from './components/ForgotPassword' 6 | import Status from './components/Status' 7 | import Settings from './components/Settings' 8 | import Attributes from './components/Attributes' 9 | import RandomNumber from './components/RandomNumber' 10 | 11 | export default () => { 12 | return ( 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /9-API-Keys/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /11-Delete-Users/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Account } from './components/Accounts' 3 | import Signup from './components/Signup' 4 | import Login from './components/Login' 5 | import ForgotPassword from './components/ForgotPassword' 6 | import Status from './components/Status' 7 | import Settings from './components/Settings' 8 | import Attributes from './components/Attributes' 9 | import RandomNumber from './components/RandomNumber' 10 | 11 | export default () => { 12 | return ( 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext, useEffect } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [status, setStatus] = useState(false); 6 | 7 | const { getSession, logout } = useContext(AccountContext); 8 | 9 | useEffect(() => { 10 | getSession() 11 | .then(session => { 12 | console.log('Session:', session); 13 | setStatus(true); 14 | }) 15 | }, []); 16 | 17 | return ( 18 |
19 | {status ? ( 20 |
21 | You are logged in. 22 | 23 |
24 | ) : 'Please login below.'} 25 |
26 | ); 27 | }; -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/Settings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | import ChangePassword from "./ChangePassword"; 4 | import ChangeEmail from "./ChangeEmail"; 5 | 6 | export default () => { 7 | const [loggedIn, setLoggedIn] = useState(false); 8 | 9 | const { getSession } = useContext(AccountContext); 10 | 11 | useEffect(() => { 12 | getSession().then(() => { 13 | setLoggedIn(true); 14 | }); 15 | }, []); 16 | 17 | return ( 18 |
19 | {loggedIn && ( 20 | <> 21 |

Settings

22 | 23 | 24 | 25 | 26 | )} 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Account } from './components/Accounts' 3 | import Signup from './components/Signup' 4 | import Login from './components/Login' 5 | import ForgotPassword from './components/ForgotPassword' 6 | import Status from './components/Status' 7 | import Settings from './components/Settings' 8 | import Attributes from './components/Attributes' 9 | import RandomNumber from './components/RandomNumber' 10 | import MFA from './components/MFA' 11 | 12 | export default () => { 13 | return ( 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /11-Delete-Users/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Account } from './components/Accounts' 3 | import Signup from './components/Signup' 4 | import Login from './components/Login' 5 | import ForgotPassword from './components/ForgotPassword' 6 | import Status from './components/Status' 7 | import Settings from './components/Settings' 8 | import Attributes from './components/Attributes' 9 | import RandomNumber from './components/RandomNumber' 10 | import MFA from './components/MFA' 11 | 12 | export default () => { 13 | return ( 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/delete-user/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 3 | 4 | const deleteUser = async (sub) => { 5 | return await new Promise((resolve, reject) => { 6 | const params = { 7 | UserPoolId: 'us-east-1_8WMsl8AMg', 8 | Username: sub, 9 | } 10 | 11 | cognito.adminDeleteUser(params, (err, data) => { 12 | if (err) { 13 | reject(err) 14 | } else { 15 | resolve(data) 16 | } 17 | }) 18 | }) 19 | } 20 | 21 | const main = async (event) => { 22 | console.log('Event:', event) 23 | return deleteUser(event.sub) 24 | } 25 | 26 | exports.handler = main 27 | 28 | // For local use only 29 | const config = require('./config.json') 30 | main({ 31 | sub: config.sub, 32 | }) 33 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/RandomNumber.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react' 2 | import rp from 'request-promise' 3 | 4 | import { AccountContext } from './Accounts' 5 | 6 | export default () => { 7 | const [number, setNumber] = useState(0) 8 | 9 | const { getSession } = useContext(AccountContext) 10 | 11 | const fetchNumber = () => { 12 | getSession().then(async ({ headers }) => { 13 | const url = 14 | 'https://yn452m1sf4.execute-api.us-east-1.amazonaws.com/dev/random-number?min=1&max=100' 15 | 16 | console.log(headers) 17 | 18 | const number = await rp(url, { headers }) 19 | setNumber(number) 20 | }) 21 | } 22 | 23 | return ( 24 |
25 |
Random number: {number}
26 | 27 |
28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/RandomNumber.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react' 2 | import rp from 'request-promise' 3 | 4 | import { AccountContext } from './Accounts' 5 | 6 | export default () => { 7 | const [number, setNumber] = useState(0) 8 | 9 | const { getSession } = useContext(AccountContext) 10 | 11 | const fetchNumber = () => { 12 | getSession().then(async ({ headers }) => { 13 | const url = 14 | 'https://yn452m1sf4.execute-api.us-east-1.amazonaws.com/dev/random-number?min=1&max=100' 15 | 16 | console.log(headers) 17 | 18 | const number = await rp(url, { headers }) 19 | setNumber(number) 20 | }) 21 | } 22 | 23 | return ( 24 |
25 |
Random number: {number}
26 | 27 |
28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/RandomNumber.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react' 2 | import rp from 'request-promise' 3 | 4 | import { AccountContext } from './Accounts' 5 | 6 | export default () => { 7 | const [number, setNumber] = useState(0) 8 | 9 | const { getSession } = useContext(AccountContext) 10 | 11 | const fetchNumber = () => { 12 | getSession().then(async ({ headers }) => { 13 | const url = 14 | 'https://yn452m1sf4.execute-api.us-east-1.amazonaws.com/dev/random-number?min=1&max=100' 15 | 16 | console.log(headers) 17 | 18 | const number = await rp(url, { headers }) 19 | setNumber(number) 20 | }) 21 | } 22 | 23 | return ( 24 |
25 |
Random number: {number}
26 | 27 |
28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/RandomNumber.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react' 2 | import rp from 'request-promise' 3 | 4 | import { AccountContext } from './Accounts' 5 | 6 | export default () => { 7 | const [number, setNumber] = useState(0) 8 | 9 | const { getSession } = useContext(AccountContext) 10 | 11 | const fetchNumber = () => { 12 | getSession().then(async ({ headers }) => { 13 | const url = 14 | 'https://yn452m1sf4.execute-api.us-east-1.amazonaws.com/dev/random-number?min=1&max=100' 15 | 16 | console.log(headers) 17 | 18 | const number = await rp(url, { headers }) 19 | setNumber(number) 20 | }) 21 | } 22 | 23 | return ( 24 |
25 |
Random number: {number}
26 | 27 |
28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /11-Delete-Users/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /2-Cognito-Signin/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import UserPool from '../UserPool'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const onSubmit = event => { 9 | event.preventDefault(); 10 | 11 | UserPool.signUp(email, password, [], null, (err, data) => { 12 | if (err) console.error(err); 13 | console.log(data); 14 | }); 15 | }; 16 | 17 | return ( 18 |
19 |
20 | setEmail(event.target.value)} 23 | /> 24 | 25 | setPassword(event.target.value)} 28 | /> 29 | 30 | 31 |
32 |
33 | ); 34 | }; -------------------------------------------------------------------------------- /1-Cognito-Signup/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /2-Cognito-Signin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "react": "*", 11 | "react-dom": "*", 12 | "react-scripts": "*" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": { 24 | "production": [ 25 | ">0.2%", 26 | "not dead", 27 | "not op_mini all" 28 | ], 29 | "development": [ 30 | "last 1 chrome version", 31 | "last 1 firefox version", 32 | "last 1 safari version" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /10-TOTP-MFA/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "axios": "^0.19.2", 11 | "react": "*", 12 | "react-dom": "*", 13 | "react-scripts": "*", 14 | "request-promise": "^4.2.5" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /9-API-Keys/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "axios": "^0.19.2", 11 | "react": "*", 12 | "react-dom": "*", 13 | "react-scripts": "*", 14 | "request-promise": "^4.2.5" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /11-Delete-Users/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "axios": "^0.19.2", 11 | "react": "*", 12 | "react-dom": "*", 13 | "react-scripts": "*", 14 | "request-promise": "^4.2.5" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/get-qr-code/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | const QR = require('qrcode') 3 | 4 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 5 | 6 | const getQRCode = async (AccessToken) => 7 | await new Promise((resolve, reject) => { 8 | cognito.associateSoftwareToken( 9 | { 10 | AccessToken, 11 | }, 12 | (err, result) => { 13 | if (err) { 14 | reject(err) 15 | } else { 16 | const name = 'Worn Off Keys' 17 | const uri = `otpauth://totp/${decodeURI(name)}?secret=${ 18 | result.SecretCode 19 | }` 20 | console.log(uri) 21 | 22 | QR.toDataURL(uri, (err, result) => { 23 | if (err) reject(err) 24 | else resolve(result) 25 | }) 26 | } 27 | } 28 | ) 29 | }) 30 | 31 | const main = async (event) => { 32 | console.log('Event:', event) 33 | return getQRCode(event.accessToken) 34 | } 35 | 36 | exports.handler = main 37 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-cognito-create-account-and-login", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "*", 7 | "@testing-library/react": "*", 8 | "@testing-library/user-event": "*", 9 | "amazon-cognito-identity-js": "*", 10 | "axios": "^0.19.2", 11 | "react": "*", 12 | "react-dom": "*", 13 | "react-scripts": "*", 14 | "request-promise": "^4.2.5" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/get-qr-code/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | const QR = require('qrcode') 3 | 4 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 5 | 6 | const getQRCode = async (AccessToken) => 7 | await new Promise((resolve, reject) => { 8 | cognito.associateSoftwareToken( 9 | { 10 | AccessToken, 11 | }, 12 | (err, result) => { 13 | if (err) { 14 | reject(err) 15 | } else { 16 | const name = 'Worn Off Keys' 17 | const uri = `otpauth://totp/${decodeURI(name)}?secret=${ 18 | result.SecretCode 19 | }` 20 | console.log(uri) 21 | 22 | QR.toDataURL(uri, (err, result) => { 23 | if (err) reject(err) 24 | else resolve(result) 25 | }) 26 | } 27 | } 28 | ) 29 | }) 30 | 31 | const main = async (event) => { 32 | console.log('Event:', event) 33 | return getQRCode(event.accessToken) 34 | } 35 | 36 | exports.handler = main 37 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /9-API-Keys/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /11-Delete-Users/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { AccountContext } from './Accounts'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const { authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | authenticate(email, password) 14 | .then(data => { 15 | console.log('Logged in!', data); 16 | }) 17 | .catch(err => { 18 | console.error('Failed to login!', err); 19 | }) 20 | }; 21 | 22 | return ( 23 |
24 |
25 | setEmail(event.target.value)} 28 | /> 29 | 30 | setPassword(event.target.value)} 33 | /> 34 | 35 | 36 |
37 |
38 | ); 39 | }; -------------------------------------------------------------------------------- /1-Cognito-Signup/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { CognitoUserPool } from 'amazon-cognito-identity-js'; 3 | 4 | export default () => { 5 | const [email, setEmail] = useState(''); 6 | const [password, setPassword] = useState(''); 7 | 8 | const poolData = { 9 | UserPoolId: 'us-east-1_8WMsl8AMg', 10 | ClientId: '41qemsprq6sqqjraln2kqr04k7' 11 | }; 12 | 13 | const UserPool = new CognitoUserPool(poolData); 14 | 15 | const onSubmit = event => { 16 | event.preventDefault(); 17 | 18 | UserPool.signUp(email, password, [], null, (err, data) => { 19 | if (err) console.error(err); 20 | console.log(data); 21 | }); 22 | }; 23 | 24 | return ( 25 |
26 |
27 | setEmail(event.target.value)} 30 | /> 31 | 32 | setPassword(event.target.value)} 35 | /> 36 | 37 | 38 |
39 |
40 | ); 41 | }; -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/Attributes.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useContext, useState } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [plan, setPlan] = useState(""); 7 | 8 | const { getSession } = useContext(AccountContext); 9 | 10 | useEffect(() => { 11 | getSession().then((data) => { 12 | setPlan(data["custom:plan"]); 13 | }); 14 | }, []); 15 | 16 | const onSubmit = (event) => { 17 | event.preventDefault(); 18 | 19 | getSession().then(({ user }) => { 20 | const attributes = [ 21 | new CognitoUserAttribute({ Name: "custom:plan", Value: plan }), 22 | ]; 23 | 24 | user.updateAttributes(attributes, (err, result) => { 25 | if (err) console.error(err); 26 | console.log(result); 27 | }); 28 | }); 29 | }; 30 | 31 | return ( 32 |
33 |

Update your plan:

34 |
35 | setPlan(event.target.value)} /> 36 | 37 | 38 |
39 |
40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/ChangePassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { AccountContext } from "./Accounts"; 3 | 4 | export default () => { 5 | const [password, setPassword] = useState(""); 6 | const [newPassword, setNewPassword] = useState(""); 7 | 8 | const { getSession, authenticate } = useContext(AccountContext); 9 | 10 | const onSubmit = event => { 11 | event.preventDefault(); 12 | 13 | getSession().then(({ user, email }) => { 14 | authenticate(email, password).then(() => { 15 | user.changePassword(password, newPassword, (err, result) => { 16 | if (err) console.error(err); 17 | console.log(result); 18 | }); 19 | }); 20 | }); 21 | }; 22 | 23 | return ( 24 |
25 |
26 | setPassword(event.target.value)} 29 | /> 30 | 31 | setNewPassword(event.target.value)} 34 | /> 35 | 36 | 37 |
38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/Attributes.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useContext, useState } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [plan, setPlan] = useState(""); 7 | 8 | const { getSession } = useContext(AccountContext); 9 | 10 | useEffect(() => { 11 | getSession().then((data) => { 12 | setPlan(data["custom:plan"]); 13 | }); 14 | }, []); 15 | 16 | const onSubmit = (event) => { 17 | event.preventDefault(); 18 | 19 | getSession().then(({ user }) => { 20 | const attributes = [ 21 | new CognitoUserAttribute({ Name: "custom:plan", Value: plan }), 22 | ]; 23 | 24 | user.updateAttributes(attributes, (err, result) => { 25 | if (err) console.error(err); 26 | console.log(result); 27 | }); 28 | }); 29 | }; 30 | 31 | return ( 32 |
33 |

Update your plan:

34 |
35 | setPlan(event.target.value)} /> 36 | 37 | 38 |
39 |
40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/Attributes.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useContext, useState } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [plan, setPlan] = useState(""); 7 | 8 | const { getSession } = useContext(AccountContext); 9 | 10 | useEffect(() => { 11 | getSession().then((data) => { 12 | setPlan(data["custom:plan"]); 13 | }); 14 | }, []); 15 | 16 | const onSubmit = (event) => { 17 | event.preventDefault(); 18 | 19 | getSession().then(({ user }) => { 20 | const attributes = [ 21 | new CognitoUserAttribute({ Name: "custom:plan", Value: plan }), 22 | ]; 23 | 24 | user.updateAttributes(attributes, (err, result) => { 25 | if (err) console.error(err); 26 | console.log(result); 27 | }); 28 | }); 29 | }; 30 | 31 | return ( 32 |
33 |

Update your plan:

34 |
35 | setPlan(event.target.value)} /> 36 | 37 | 38 |
39 |
40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/Attributes.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useContext, useState } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [plan, setPlan] = useState(""); 7 | 8 | const { getSession } = useContext(AccountContext); 9 | 10 | useEffect(() => { 11 | getSession().then((data) => { 12 | setPlan(data["custom:plan"]); 13 | }); 14 | }, []); 15 | 16 | const onSubmit = (event) => { 17 | event.preventDefault(); 18 | 19 | getSession().then(({ user }) => { 20 | const attributes = [ 21 | new CognitoUserAttribute({ Name: "custom:plan", Value: plan }), 22 | ]; 23 | 24 | user.updateAttributes(attributes, (err, result) => { 25 | if (err) console.error(err); 26 | console.log(result); 27 | }); 28 | }); 29 | }; 30 | 31 | return ( 32 |
33 |

Update your plan:

34 |
35 | setPlan(event.target.value)} /> 36 | 37 | 38 |
39 |
40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/Attributes.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useContext, useState } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [plan, setPlan] = useState(""); 7 | 8 | const { getSession } = useContext(AccountContext); 9 | 10 | useEffect(() => { 11 | getSession().then((data) => { 12 | setPlan(data["custom:plan"]); 13 | }); 14 | }, []); 15 | 16 | const onSubmit = (event) => { 17 | event.preventDefault(); 18 | 19 | getSession().then(({ user }) => { 20 | const attributes = [ 21 | new CognitoUserAttribute({ Name: "custom:plan", Value: plan }), 22 | ]; 23 | 24 | user.updateAttributes(attributes, (err, result) => { 25 | if (err) console.error(err); 26 | console.log(result); 27 | }); 28 | }); 29 | }; 30 | 31 | return ( 32 |
33 |

Update your plan:

34 |
35 | setPlan(event.target.value)} /> 36 | 37 | 38 |
39 |
40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/disable-mfa/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | 3 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 4 | 5 | const validateMFA = async (UserCode, AccessToken) => 6 | await new Promise((resolve, reject) => { 7 | const params = { 8 | AccessToken, 9 | UserCode, 10 | } 11 | 12 | cognito.verifySoftwareToken(params, (err, result) => { 13 | if (err) reject(err) 14 | else resolve(result) 15 | }) 16 | }) 17 | 18 | const disableMFA = async (sub) => 19 | await new Promise((resolve, reject) => { 20 | const params = { 21 | UserPoolId: 'us-east-1_8WMsl8AMg', 22 | Username: sub, 23 | SoftwareTokenMfaSettings: { 24 | Enabled: false, 25 | }, 26 | } 27 | 28 | cognito.adminSetUserMFAPreference(params, (err, result) => { 29 | if (err) reject(err) 30 | else resolve(result) 31 | }) 32 | }) 33 | 34 | const main = async (event) => { 35 | console.log('Event:', event) 36 | 37 | const { accessToken, sub, userCode } = event 38 | 39 | const validated = await validateMFA(userCode, accessToken) 40 | 41 | if (validated.Status && validated.Status === 'SUCCESS') { 42 | return await disableMFA(sub) 43 | } 44 | 45 | return validated 46 | } 47 | 48 | exports.handler = main 49 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/disable-mfa/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk') 2 | 3 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 4 | 5 | const validateMFA = async (UserCode, AccessToken) => 6 | await new Promise((resolve, reject) => { 7 | const params = { 8 | AccessToken, 9 | UserCode, 10 | } 11 | 12 | cognito.verifySoftwareToken(params, (err, result) => { 13 | if (err) reject(err) 14 | else resolve(result) 15 | }) 16 | }) 17 | 18 | const disableMFA = async (sub) => 19 | await new Promise((resolve, reject) => { 20 | const params = { 21 | UserPoolId: 'us-east-1_8WMsl8AMg', 22 | Username: sub, 23 | SoftwareTokenMfaSettings: { 24 | Enabled: false, 25 | }, 26 | } 27 | 28 | cognito.adminSetUserMFAPreference(params, (err, result) => { 29 | if (err) reject(err) 30 | else resolve(result) 31 | }) 32 | }) 33 | 34 | const main = async (event) => { 35 | console.log('Event:', event) 36 | 37 | const { accessToken, sub, userCode } = event 38 | 39 | const validated = await validateMFA(userCode, accessToken) 40 | 41 | if (validated.Status && validated.Status === 'SUCCESS') { 42 | return await disableMFA(sub) 43 | } 44 | 45 | return validated 46 | } 47 | 48 | exports.handler = main 49 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/ChangeEmail.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { CognitoUserAttribute } from "amazon-cognito-identity-js"; 3 | import { AccountContext } from "./Accounts"; 4 | 5 | export default () => { 6 | const [newEmail, setNewEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const { getSession, authenticate } = useContext(AccountContext); 10 | 11 | const onSubmit = event => { 12 | event.preventDefault(); 13 | 14 | getSession().then(({ user, email }) => { 15 | authenticate(email, password).then(() => { 16 | const attributes = [ 17 | new CognitoUserAttribute({ Name: "email", Value: newEmail }) 18 | ]; 19 | 20 | user.updateAttributes(attributes, (err, results) => { 21 | if (err) console.error(err); 22 | console.log(results); 23 | }); 24 | }); 25 | }); 26 | }; 27 | 28 | return ( 29 |
30 |
31 | setNewEmail(event.target.value)} 34 | /> 35 | 36 | setPassword(event.target.value)} 39 | /> 40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /2-Cognito-Signin/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser, AuthenticationDetails } from "amazon-cognito-identity-js"; 3 | import UserPool from "../UserPool"; 4 | 5 | export default () => { 6 | const [email, setEmail] = useState(""); 7 | const [password, setPassword] = useState(""); 8 | 9 | const onSubmit = event => { 10 | event.preventDefault(); 11 | 12 | const user = new CognitoUser({ 13 | Username: email, 14 | Pool: UserPool 15 | }); 16 | const authDetails = new AuthenticationDetails({ 17 | Username: email, 18 | Password: password 19 | }); 20 | 21 | user.authenticateUser(authDetails, { 22 | onSuccess: data => { 23 | console.log("onSuccess:", data); 24 | }, 25 | 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | 30 | newPasswordRequired: data => { 31 | console.log("newPasswordRequired:", data); 32 | } 33 | }); 34 | }; 35 | 36 | return ( 37 |
38 |
39 | setEmail(event.target.value)} /> 40 | 41 | setPassword(event.target.value)} 44 | /> 45 | 46 | 47 |
48 |
49 | ); 50 | }; 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | static/*.css 3 | static/*.css.map 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | 12 | # Diagnostic reports (https://nodejs.org/api/report.html) 13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | *.pid.lock 20 | 21 | # Directory for instrumented libs generated by jscoverage/JSCover 22 | lib-cov 23 | 24 | # Coverage directory used by tools like istanbul 25 | coverage 26 | 27 | # nyc test coverage 28 | .nyc_output 29 | 30 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 31 | .grunt 32 | 33 | # Bower dependency directory (https://bower.io/) 34 | bower_components 35 | 36 | # node-waf configuration 37 | .lock-wscript 38 | 39 | # Compiled binary addons (https://nodejs.org/api/addons.html) 40 | build/Release 41 | 42 | # Dependency directories 43 | node_modules/ 44 | jspm_packages/ 45 | 46 | # TypeScript v1 declaration files 47 | typings/ 48 | 49 | # Optional npm cache directory 50 | .npm 51 | 52 | # Optional eslint cache 53 | .eslintcache 54 | 55 | # Optional REPL history 56 | .node_repl_history 57 | 58 | # Output of 'npm pack' 59 | *.tgz 60 | 61 | # Yarn Integrity file 62 | .yarn-integrity 63 | 64 | # dotenv environment variables file 65 | .env 66 | .env.test 67 | 68 | # parcel-bundler cache (https://parceljs.org/) 69 | .cache 70 | 71 | # next.js build output 72 | .next 73 | 74 | # nuxt.js build output 75 | .nuxt 76 | 77 | # vuepress build output 78 | .vuepress/dist 79 | 80 | # Serverless directories 81 | .serverless/ 82 | 83 | # FuseBox cache 84 | .fusebox/ 85 | 86 | # DynamoDB Local files 87 | .dynamodb/ -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from 'react'; 2 | import { CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js'; 3 | import Pool from '../UserPool'; 4 | 5 | const AccountContext = createContext(); 6 | 7 | const Account = props => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser(); 11 | if (user) { 12 | user.getSession((err, session) => { 13 | if (err) { 14 | reject(); 15 | } else { 16 | resolve(session); 17 | } 18 | }); 19 | } else { 20 | reject(); 21 | } 22 | }); 23 | 24 | const authenticate = async (Username, Password) => 25 | await new Promise((resolve, reject) => { 26 | const user = new CognitoUser({ Username, Pool }); 27 | const authDetails = new AuthenticationDetails({ Username, Password }); 28 | 29 | user.authenticateUser(authDetails, { 30 | onSuccess: data => { 31 | console.log('onSuccess:', data); 32 | resolve(data); 33 | }, 34 | 35 | onFailure: err => { 36 | console.error('onFailure:', err); 37 | reject(err); 38 | }, 39 | 40 | newPasswordRequired: data => { 41 | console.log('newPasswordRequired:', data); 42 | resolve(data); 43 | } 44 | }); 45 | }); 46 | 47 | const logout = () => { 48 | const user = Pool.getCurrentUser(); 49 | if (user) { 50 | user.signOut(); 51 | } 52 | } 53 | 54 | return ( 55 | 60 | {props.children} 61 | 62 | ); 63 | }; 64 | 65 | export { Account, AccountContext }; -------------------------------------------------------------------------------- /10-TOTP-MFA/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /9-API-Keys/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /1-Cognito-Signup/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /11-Delete-Users/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /2-Cognito-Signin/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /3-Cognito-Sessions-Logout/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /9-API-Keys/lambda/index.js: -------------------------------------------------------------------------------- 1 | const { APIGateway, CognitoIdentityServiceProvider } = require('aws-sdk') 2 | 3 | const API = new APIGateway({ region: 'us-east-1' }) 4 | const cognito = new CognitoIdentityServiceProvider({ region: 'us-east-1' }) 5 | 6 | const generateApiKey = async (sub) => { 7 | return await new Promise((resolve, reject) => { 8 | const params = { 9 | name: `tutorial-${sub}`, 10 | generateDistinctId: true, 11 | enabled: true, 12 | stageKeys: [ 13 | { 14 | restApiId: 'yn452m1sf4', 15 | stageName: 'dev', 16 | }, 17 | ], 18 | } 19 | 20 | API.createApiKey(params, (err, results) => { 21 | if (err) reject(err) 22 | else resolve(results) 23 | }) 24 | }) 25 | } 26 | 27 | const addToPlan = async (keyId) => { 28 | return await new Promise((resolve, reject) => { 29 | const params = { 30 | keyId, 31 | keyType: 'API_KEY', 32 | usagePlanId: 'x5iccy', 33 | } 34 | 35 | API.createUsagePlanKey(params, (err, results) => { 36 | if (err) reject(err) 37 | else resolve(results) 38 | }) 39 | }) 40 | } 41 | 42 | const saveApiKey = async (sub, apikey) => { 43 | return await new Promise((resolve, reject) => { 44 | const params = { 45 | UserAttributes: [ 46 | { 47 | Name: 'custom:apikey', 48 | Value: apikey, 49 | }, 50 | ], 51 | Username: sub, 52 | UserPoolId: 'us-east-1_8WMsl8AMg', 53 | } 54 | 55 | cognito.adminUpdateUserAttributes(params, (err, results) => { 56 | if (err) reject(err) 57 | else resolve(results) 58 | }) 59 | }) 60 | } 61 | 62 | const main = async (event) => { 63 | console.log('Event:', event) 64 | 65 | if (event.triggerSource == 'PostConfirmation_ConfirmSignUp') { 66 | const { sub } = event.request.userAttributes 67 | const { id, value: apikey } = await generateApiKey(sub) 68 | await addToPlan(id) 69 | await saveApiKey(sub, apikey) 70 | } 71 | 72 | return event 73 | } 74 | 75 | exports.handler = main 76 | -------------------------------------------------------------------------------- /10-TOTP-MFA/lambda/create-api-key/index.js: -------------------------------------------------------------------------------- 1 | const { APIGateway, CognitoIdentityServiceProvider } = require('aws-sdk') 2 | 3 | const API = new APIGateway({ region: 'us-east-1' }) 4 | const cognito = new CognitoIdentityServiceProvider({ region: 'us-east-1' }) 5 | 6 | const generateApiKey = async (sub) => { 7 | return await new Promise((resolve, reject) => { 8 | const params = { 9 | name: `tutorial-${sub}`, 10 | generateDistinctId: true, 11 | enabled: true, 12 | stageKeys: [ 13 | { 14 | restApiId: 'yn452m1sf4', 15 | stageName: 'dev', 16 | }, 17 | ], 18 | } 19 | 20 | API.createApiKey(params, (err, results) => { 21 | if (err) reject(err) 22 | else resolve(results) 23 | }) 24 | }) 25 | } 26 | 27 | const addToPlan = async (keyId) => { 28 | return await new Promise((resolve, reject) => { 29 | const params = { 30 | keyId, 31 | keyType: 'API_KEY', 32 | usagePlanId: 'x5iccy', 33 | } 34 | 35 | API.createUsagePlanKey(params, (err, results) => { 36 | if (err) reject(err) 37 | else resolve(results) 38 | }) 39 | }) 40 | } 41 | 42 | const saveApiKey = async (sub, apikey) => { 43 | return await new Promise((resolve, reject) => { 44 | const params = { 45 | UserAttributes: [ 46 | { 47 | Name: 'custom:apikey', 48 | Value: apikey, 49 | }, 50 | ], 51 | Username: sub, 52 | UserPoolId: 'us-east-1_8WMsl8AMg', 53 | } 54 | 55 | cognito.adminUpdateUserAttributes(params, (err, results) => { 56 | if (err) reject(err) 57 | else resolve(results) 58 | }) 59 | }) 60 | } 61 | 62 | const main = async (event) => { 63 | console.log('Event:', event) 64 | 65 | if (event.triggerSource == 'PostConfirmation_ConfirmSignUp') { 66 | const { sub } = event.request.userAttributes 67 | const { id, value: apikey } = await generateApiKey(sub) 68 | await addToPlan(id) 69 | await saveApiKey(sub, apikey) 70 | } 71 | 72 | return event 73 | } 74 | 75 | exports.handler = main 76 | -------------------------------------------------------------------------------- /11-Delete-Users/lambda/create-api-key/index.js: -------------------------------------------------------------------------------- 1 | const { APIGateway, CognitoIdentityServiceProvider } = require('aws-sdk') 2 | 3 | const API = new APIGateway({ region: 'us-east-1' }) 4 | const cognito = new CognitoIdentityServiceProvider({ region: 'us-east-1' }) 5 | 6 | const generateApiKey = async (sub) => { 7 | return await new Promise((resolve, reject) => { 8 | const params = { 9 | name: `tutorial-${sub}`, 10 | generateDistinctId: true, 11 | enabled: true, 12 | stageKeys: [ 13 | { 14 | restApiId: 'yn452m1sf4', 15 | stageName: 'dev', 16 | }, 17 | ], 18 | } 19 | 20 | API.createApiKey(params, (err, results) => { 21 | if (err) reject(err) 22 | else resolve(results) 23 | }) 24 | }) 25 | } 26 | 27 | const addToPlan = async (keyId) => { 28 | return await new Promise((resolve, reject) => { 29 | const params = { 30 | keyId, 31 | keyType: 'API_KEY', 32 | usagePlanId: 'x5iccy', 33 | } 34 | 35 | API.createUsagePlanKey(params, (err, results) => { 36 | if (err) reject(err) 37 | else resolve(results) 38 | }) 39 | }) 40 | } 41 | 42 | const saveApiKey = async (sub, apikey) => { 43 | return await new Promise((resolve, reject) => { 44 | const params = { 45 | UserAttributes: [ 46 | { 47 | Name: 'custom:apikey', 48 | Value: apikey, 49 | }, 50 | ], 51 | Username: sub, 52 | UserPoolId: 'us-east-1_8WMsl8AMg', 53 | } 54 | 55 | cognito.adminUpdateUserAttributes(params, (err, results) => { 56 | if (err) reject(err) 57 | else resolve(results) 58 | }) 59 | }) 60 | } 61 | 62 | const main = async (event) => { 63 | console.log('Event:', event) 64 | 65 | if (event.triggerSource == 'PostConfirmation_ConfirmSignUp') { 66 | const { sub } = event.request.userAttributes 67 | const { id, value: apikey } = await generateApiKey(sub) 68 | await addToPlan(id) 69 | await saveApiKey(sub, apikey) 70 | } 71 | 72 | return event 73 | } 74 | 75 | exports.handler = main 76 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | export default () => { 6 | const [stage, setStage] = useState(1); // 1 = email stage, 2 = code stage 7 | const [email, setEmail] = useState(""); 8 | const [code, setCode] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [confirmPassword, setConfirmPassword] = useState(""); 11 | 12 | const getUser = () => { 13 | return new CognitoUser({ 14 | Username: email.toLowerCase(), 15 | Pool 16 | }); 17 | }; 18 | 19 | const sendCode = event => { 20 | event.preventDefault(); 21 | 22 | getUser().forgotPassword({ 23 | onSuccess: data => { 24 | console.log("onSuccess:", data); 25 | }, 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | inputVerificationCode: data => { 30 | console.log("Input code:", data); 31 | setStage(2); 32 | } 33 | }); 34 | }; 35 | 36 | const resetPassword = event => { 37 | event.preventDefault(); 38 | 39 | if (password !== confirmPassword) { 40 | console.error("Passwords are not the same"); 41 | return; 42 | } 43 | 44 | getUser().confirmPassword(code, password, { 45 | onSuccess: data => { 46 | console.log("onSuccess:", data); 47 | }, 48 | onFailure: err => { 49 | console.error("onFailure:", err); 50 | } 51 | }); 52 | }; 53 | 54 | return ( 55 |
56 | {stage === 1 && ( 57 |
58 | setEmail(event.target.value)} 61 | /> 62 | 63 |
64 | )} 65 | 66 | {stage === 2 && ( 67 |
68 | setCode(event.target.value)} /> 69 | setPassword(event.target.value)} 72 | /> 73 | setConfirmPassword(event.target.value)} 76 | /> 77 | 78 |
79 | )} 80 |
81 | ); 82 | }; 83 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | export default () => { 6 | const [stage, setStage] = useState(1); // 1 = email stage, 2 = code stage 7 | const [email, setEmail] = useState(""); 8 | const [code, setCode] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [confirmPassword, setConfirmPassword] = useState(""); 11 | 12 | const getUser = () => { 13 | return new CognitoUser({ 14 | Username: email.toLowerCase(), 15 | Pool 16 | }); 17 | }; 18 | 19 | const sendCode = event => { 20 | event.preventDefault(); 21 | 22 | getUser().forgotPassword({ 23 | onSuccess: data => { 24 | console.log("onSuccess:", data); 25 | }, 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | inputVerificationCode: data => { 30 | console.log("Input code:", data); 31 | setStage(2); 32 | } 33 | }); 34 | }; 35 | 36 | const resetPassword = event => { 37 | event.preventDefault(); 38 | 39 | if (password !== confirmPassword) { 40 | console.error("Passwords are not the same"); 41 | return; 42 | } 43 | 44 | getUser().confirmPassword(code, password, { 45 | onSuccess: data => { 46 | console.log("onSuccess:", data); 47 | }, 48 | onFailure: err => { 49 | console.error("onFailure:", err); 50 | } 51 | }); 52 | }; 53 | 54 | return ( 55 |
56 | {stage === 1 && ( 57 |
58 | setEmail(event.target.value)} 61 | /> 62 | 63 |
64 | )} 65 | 66 | {stage === 2 && ( 67 |
68 | setCode(event.target.value)} /> 69 | setPassword(event.target.value)} 72 | /> 73 | setConfirmPassword(event.target.value)} 76 | /> 77 | 78 |
79 | )} 80 |
81 | ); 82 | }; 83 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | export default () => { 6 | const [stage, setStage] = useState(1); // 1 = email stage, 2 = code stage 7 | const [email, setEmail] = useState(""); 8 | const [code, setCode] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [confirmPassword, setConfirmPassword] = useState(""); 11 | 12 | const getUser = () => { 13 | return new CognitoUser({ 14 | Username: email.toLowerCase(), 15 | Pool 16 | }); 17 | }; 18 | 19 | const sendCode = event => { 20 | event.preventDefault(); 21 | 22 | getUser().forgotPassword({ 23 | onSuccess: data => { 24 | console.log("onSuccess:", data); 25 | }, 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | inputVerificationCode: data => { 30 | console.log("Input code:", data); 31 | setStage(2); 32 | } 33 | }); 34 | }; 35 | 36 | const resetPassword = event => { 37 | event.preventDefault(); 38 | 39 | if (password !== confirmPassword) { 40 | console.error("Passwords are not the same"); 41 | return; 42 | } 43 | 44 | getUser().confirmPassword(code, password, { 45 | onSuccess: data => { 46 | console.log("onSuccess:", data); 47 | }, 48 | onFailure: err => { 49 | console.error("onFailure:", err); 50 | } 51 | }); 52 | }; 53 | 54 | return ( 55 |
56 | {stage === 1 && ( 57 |
58 | setEmail(event.target.value)} 61 | /> 62 | 63 |
64 | )} 65 | 66 | {stage === 2 && ( 67 |
68 | setCode(event.target.value)} /> 69 | setPassword(event.target.value)} 72 | /> 73 | setConfirmPassword(event.target.value)} 76 | /> 77 | 78 |
79 | )} 80 |
81 | ); 82 | }; 83 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | export default () => { 6 | const [stage, setStage] = useState(1); // 1 = email stage, 2 = code stage 7 | const [email, setEmail] = useState(""); 8 | const [code, setCode] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [confirmPassword, setConfirmPassword] = useState(""); 11 | 12 | const getUser = () => { 13 | return new CognitoUser({ 14 | Username: email.toLowerCase(), 15 | Pool 16 | }); 17 | }; 18 | 19 | const sendCode = event => { 20 | event.preventDefault(); 21 | 22 | getUser().forgotPassword({ 23 | onSuccess: data => { 24 | console.log("onSuccess:", data); 25 | }, 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | inputVerificationCode: data => { 30 | console.log("Input code:", data); 31 | setStage(2); 32 | } 33 | }); 34 | }; 35 | 36 | const resetPassword = event => { 37 | event.preventDefault(); 38 | 39 | if (password !== confirmPassword) { 40 | console.error("Passwords are not the same"); 41 | return; 42 | } 43 | 44 | getUser().confirmPassword(code, password, { 45 | onSuccess: data => { 46 | console.log("onSuccess:", data); 47 | }, 48 | onFailure: err => { 49 | console.error("onFailure:", err); 50 | } 51 | }); 52 | }; 53 | 54 | return ( 55 |
56 | {stage === 1 && ( 57 |
58 | setEmail(event.target.value)} 61 | /> 62 | 63 |
64 | )} 65 | 66 | {stage === 2 && ( 67 |
68 | setCode(event.target.value)} /> 69 | setPassword(event.target.value)} 72 | /> 73 | setConfirmPassword(event.target.value)} 76 | /> 77 | 78 |
79 | )} 80 |
81 | ); 82 | }; 83 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | export default () => { 6 | const [stage, setStage] = useState(1); // 1 = email stage, 2 = code stage 7 | const [email, setEmail] = useState(""); 8 | const [code, setCode] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [confirmPassword, setConfirmPassword] = useState(""); 11 | 12 | const getUser = () => { 13 | return new CognitoUser({ 14 | Username: email.toLowerCase(), 15 | Pool 16 | }); 17 | }; 18 | 19 | const sendCode = event => { 20 | event.preventDefault(); 21 | 22 | getUser().forgotPassword({ 23 | onSuccess: data => { 24 | console.log("onSuccess:", data); 25 | }, 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | inputVerificationCode: data => { 30 | console.log("Input code:", data); 31 | setStage(2); 32 | } 33 | }); 34 | }; 35 | 36 | const resetPassword = event => { 37 | event.preventDefault(); 38 | 39 | if (password !== confirmPassword) { 40 | console.error("Passwords are not the same"); 41 | return; 42 | } 43 | 44 | getUser().confirmPassword(code, password, { 45 | onSuccess: data => { 46 | console.log("onSuccess:", data); 47 | }, 48 | onFailure: err => { 49 | console.error("onFailure:", err); 50 | } 51 | }); 52 | }; 53 | 54 | return ( 55 |
56 | {stage === 1 && ( 57 |
58 | setEmail(event.target.value)} 61 | /> 62 | 63 |
64 | )} 65 | 66 | {stage === 2 && ( 67 |
68 | setCode(event.target.value)} /> 69 | setPassword(event.target.value)} 72 | /> 73 | setConfirmPassword(event.target.value)} 76 | /> 77 | 78 |
79 | )} 80 |
81 | ); 82 | }; 83 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { CognitoUser } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | export default () => { 6 | const [stage, setStage] = useState(1); // 1 = email stage, 2 = code stage 7 | const [email, setEmail] = useState(""); 8 | const [code, setCode] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [confirmPassword, setConfirmPassword] = useState(""); 11 | 12 | const getUser = () => { 13 | return new CognitoUser({ 14 | Username: email.toLowerCase(), 15 | Pool 16 | }); 17 | }; 18 | 19 | const sendCode = event => { 20 | event.preventDefault(); 21 | 22 | getUser().forgotPassword({ 23 | onSuccess: data => { 24 | console.log("onSuccess:", data); 25 | }, 26 | onFailure: err => { 27 | console.error("onFailure:", err); 28 | }, 29 | inputVerificationCode: data => { 30 | console.log("Input code:", data); 31 | setStage(2); 32 | } 33 | }); 34 | }; 35 | 36 | const resetPassword = event => { 37 | event.preventDefault(); 38 | 39 | if (password !== confirmPassword) { 40 | console.error("Passwords are not the same"); 41 | return; 42 | } 43 | 44 | getUser().confirmPassword(code, password, { 45 | onSuccess: data => { 46 | console.log("onSuccess:", data); 47 | }, 48 | onFailure: err => { 49 | console.error("onFailure:", err); 50 | } 51 | }); 52 | }; 53 | 54 | return ( 55 |
56 | {stage === 1 && ( 57 |
58 | setEmail(event.target.value)} 61 | /> 62 | 63 |
64 | )} 65 | 66 | {stage === 2 && ( 67 |
68 | setCode(event.target.value)} /> 69 | setPassword(event.target.value)} 72 | /> 73 | setConfirmPassword(event.target.value)} 76 | /> 77 | 78 |
79 | )} 80 |
81 | ); 82 | }; 83 | -------------------------------------------------------------------------------- /5-Cognito-Change-Email/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from "react"; 2 | import { CognitoUser, AuthenticationDetails } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | const AccountContext = createContext(); 6 | 7 | const Account = props => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser(); 11 | if (user) { 12 | user.getSession(async (err, session) => { 13 | if (err) { 14 | reject(); 15 | } else { 16 | const attributes = await new Promise((resolve, reject) => { 17 | user.getUserAttributes((err, attributes) => { 18 | if (err) { 19 | reject(err); 20 | } else { 21 | const results = {}; 22 | 23 | for (let attribute of attributes) { 24 | const { Name, Value } = attribute; 25 | results[Name] = Value; 26 | } 27 | 28 | resolve(results); 29 | } 30 | }); 31 | }); 32 | 33 | resolve({ 34 | user, 35 | ...session, 36 | ...attributes 37 | }); 38 | } 39 | }); 40 | } else { 41 | reject(); 42 | } 43 | }); 44 | 45 | const authenticate = async (Username, Password) => 46 | await new Promise((resolve, reject) => { 47 | const user = new CognitoUser({ Username, Pool }); 48 | const authDetails = new AuthenticationDetails({ Username, Password }); 49 | 50 | user.authenticateUser(authDetails, { 51 | onSuccess: data => { 52 | console.log("onSuccess:", data); 53 | resolve(data); 54 | }, 55 | 56 | onFailure: err => { 57 | console.error("onFailure:", err); 58 | reject(err); 59 | }, 60 | 61 | newPasswordRequired: data => { 62 | console.log("newPasswordRequired:", data); 63 | resolve(data); 64 | } 65 | }); 66 | }); 67 | 68 | const logout = () => { 69 | const user = Pool.getCurrentUser(); 70 | if (user) { 71 | user.signOut(); 72 | } 73 | }; 74 | 75 | return ( 76 | 83 | {props.children} 84 | 85 | ); 86 | }; 87 | 88 | export { Account, AccountContext }; 89 | -------------------------------------------------------------------------------- /4-Cognito-Change-Password/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from "react"; 2 | import { CognitoUser, AuthenticationDetails } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | const AccountContext = createContext(); 6 | 7 | const Account = props => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser(); 11 | if (user) { 12 | user.getSession(async (err, session) => { 13 | if (err) { 14 | reject(); 15 | } else { 16 | const attributes = await new Promise((resolve, reject) => { 17 | user.getUserAttributes((err, attributes) => { 18 | if (err) { 19 | reject(err); 20 | } else { 21 | const results = {}; 22 | 23 | for (let attribute of attributes) { 24 | const { Name, Value } = attribute; 25 | results[Name] = Value; 26 | } 27 | 28 | resolve(results); 29 | } 30 | }); 31 | }); 32 | 33 | resolve({ 34 | user, 35 | ...session, 36 | ...attributes 37 | }); 38 | } 39 | }); 40 | } else { 41 | reject(); 42 | } 43 | }); 44 | 45 | const authenticate = async (Username, Password) => 46 | await new Promise((resolve, reject) => { 47 | const user = new CognitoUser({ Username, Pool }); 48 | const authDetails = new AuthenticationDetails({ Username, Password }); 49 | 50 | user.authenticateUser(authDetails, { 51 | onSuccess: data => { 52 | console.log("onSuccess:", data); 53 | resolve(data); 54 | }, 55 | 56 | onFailure: err => { 57 | console.error("onFailure:", err); 58 | reject(err); 59 | }, 60 | 61 | newPasswordRequired: data => { 62 | console.log("newPasswordRequired:", data); 63 | resolve(data); 64 | } 65 | }); 66 | }); 67 | 68 | const logout = () => { 69 | const user = Pool.getCurrentUser(); 70 | if (user) { 71 | user.signOut(); 72 | } 73 | }; 74 | 75 | return ( 76 | 83 | {props.children} 84 | 85 | ); 86 | }; 87 | 88 | export { Account, AccountContext }; 89 | -------------------------------------------------------------------------------- /6-Cognito-Forgot-Password/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from "react"; 2 | import { CognitoUser, AuthenticationDetails } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | const AccountContext = createContext(); 6 | 7 | const Account = props => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser(); 11 | if (user) { 12 | user.getSession(async (err, session) => { 13 | if (err) { 14 | reject(); 15 | } else { 16 | const attributes = await new Promise((resolve, reject) => { 17 | user.getUserAttributes((err, attributes) => { 18 | if (err) { 19 | reject(err); 20 | } else { 21 | const results = {}; 22 | 23 | for (let attribute of attributes) { 24 | const { Name, Value } = attribute; 25 | results[Name] = Value; 26 | } 27 | 28 | resolve(results); 29 | } 30 | }); 31 | }); 32 | 33 | resolve({ 34 | user, 35 | ...session, 36 | ...attributes 37 | }); 38 | } 39 | }); 40 | } else { 41 | reject(); 42 | } 43 | }); 44 | 45 | const authenticate = async (Username, Password) => 46 | await new Promise((resolve, reject) => { 47 | const user = new CognitoUser({ Username, Pool }); 48 | const authDetails = new AuthenticationDetails({ Username, Password }); 49 | 50 | user.authenticateUser(authDetails, { 51 | onSuccess: data => { 52 | console.log("onSuccess:", data); 53 | resolve(data); 54 | }, 55 | 56 | onFailure: err => { 57 | console.error("onFailure:", err); 58 | reject(err); 59 | }, 60 | 61 | newPasswordRequired: data => { 62 | console.log("newPasswordRequired:", data); 63 | resolve(data); 64 | } 65 | }); 66 | }); 67 | 68 | const logout = () => { 69 | const user = Pool.getCurrentUser(); 70 | if (user) { 71 | user.signOut(); 72 | } 73 | }; 74 | 75 | return ( 76 | 83 | {props.children} 84 | 85 | ); 86 | }; 87 | 88 | export { Account, AccountContext }; 89 | -------------------------------------------------------------------------------- /7-Cognito-User-Attributes/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from "react"; 2 | import { CognitoUser, AuthenticationDetails } from "amazon-cognito-identity-js"; 3 | import Pool from "../UserPool"; 4 | 5 | const AccountContext = createContext(); 6 | 7 | const Account = props => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser(); 11 | if (user) { 12 | user.getSession(async (err, session) => { 13 | if (err) { 14 | reject(); 15 | } else { 16 | const attributes = await new Promise((resolve, reject) => { 17 | user.getUserAttributes((err, attributes) => { 18 | if (err) { 19 | reject(err); 20 | } else { 21 | const results = {}; 22 | 23 | for (let attribute of attributes) { 24 | const { Name, Value } = attribute; 25 | results[Name] = Value; 26 | } 27 | 28 | resolve(results); 29 | } 30 | }); 31 | }); 32 | 33 | resolve({ 34 | user, 35 | ...session, 36 | ...attributes 37 | }); 38 | } 39 | }); 40 | } else { 41 | reject(); 42 | } 43 | }); 44 | 45 | const authenticate = async (Username, Password) => 46 | await new Promise((resolve, reject) => { 47 | const user = new CognitoUser({ Username, Pool }); 48 | const authDetails = new AuthenticationDetails({ Username, Password }); 49 | 50 | user.authenticateUser(authDetails, { 51 | onSuccess: data => { 52 | console.log("onSuccess:", data); 53 | resolve(data); 54 | }, 55 | 56 | onFailure: err => { 57 | console.error("onFailure:", err); 58 | reject(err); 59 | }, 60 | 61 | newPasswordRequired: data => { 62 | console.log("newPasswordRequired:", data); 63 | resolve(data); 64 | } 65 | }); 66 | }); 67 | 68 | const logout = () => { 69 | const user = Pool.getCurrentUser(); 70 | if (user) { 71 | user.signOut(); 72 | } 73 | }; 74 | 75 | return ( 76 | 83 | {props.children} 84 | 85 | ); 86 | }; 87 | 88 | export { Account, AccountContext }; 89 | -------------------------------------------------------------------------------- /8-API-Gateway-Authorization/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from 'react' 2 | import { CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js' 3 | import Pool from '../UserPool' 4 | 5 | const AccountContext = createContext() 6 | 7 | const Account = (props) => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser() 11 | if (user) { 12 | user.getSession(async (err, session) => { 13 | if (err) { 14 | reject() 15 | } else { 16 | const attributes = await new Promise((resolve, reject) => { 17 | user.getUserAttributes((err, attributes) => { 18 | if (err) { 19 | reject(err) 20 | } else { 21 | const results = {} 22 | 23 | for (let attribute of attributes) { 24 | const { Name, Value } = attribute 25 | results[Name] = Value 26 | } 27 | 28 | resolve(results) 29 | } 30 | }) 31 | }) 32 | 33 | const token = session.getIdToken().getJwtToken() 34 | 35 | resolve({ 36 | user, 37 | headers: { 38 | Authorization: token, 39 | }, 40 | ...session, 41 | ...attributes, 42 | }) 43 | } 44 | }) 45 | } else { 46 | reject() 47 | } 48 | }) 49 | 50 | const authenticate = async (Username, Password) => 51 | await new Promise((resolve, reject) => { 52 | const user = new CognitoUser({ Username, Pool }) 53 | const authDetails = new AuthenticationDetails({ Username, Password }) 54 | 55 | user.authenticateUser(authDetails, { 56 | onSuccess: (data) => { 57 | console.log('onSuccess:', data) 58 | resolve(data) 59 | }, 60 | 61 | onFailure: (err) => { 62 | console.error('onFailure:', err) 63 | reject(err) 64 | }, 65 | 66 | newPasswordRequired: (data) => { 67 | console.log('newPasswordRequired:', data) 68 | resolve(data) 69 | }, 70 | }) 71 | }) 72 | 73 | const logout = () => { 74 | const user = Pool.getCurrentUser() 75 | if (user) { 76 | user.signOut() 77 | } 78 | } 79 | 80 | return ( 81 | 88 | {props.children} 89 | 90 | ) 91 | } 92 | 93 | export { Account, AccountContext } 94 | -------------------------------------------------------------------------------- /9-API-Keys/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from 'react' 2 | import { CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js' 3 | import Pool from '../UserPool' 4 | 5 | const AccountContext = createContext() 6 | 7 | const Account = (props) => { 8 | const getSession = async () => 9 | await new Promise((resolve, reject) => { 10 | const user = Pool.getCurrentUser() 11 | if (user) { 12 | user.getSession(async (err, session) => { 13 | if (err) { 14 | reject() 15 | } else { 16 | const attributes = await new Promise((resolve, reject) => { 17 | user.getUserAttributes((err, attributes) => { 18 | if (err) { 19 | reject(err) 20 | } else { 21 | console.log('attributes:', attributes) 22 | const results = {} 23 | 24 | for (let attribute of attributes) { 25 | const { Name, Value } = attribute 26 | results[Name] = Value 27 | } 28 | 29 | resolve(results) 30 | } 31 | }) 32 | }) 33 | 34 | const token = session.getIdToken().getJwtToken() 35 | 36 | resolve({ 37 | user, 38 | headers: { 39 | 'x-api-key': attributes['custom:apikey'], 40 | Authorization: token, 41 | }, 42 | ...session, 43 | ...attributes, 44 | }) 45 | } 46 | }) 47 | } else { 48 | reject() 49 | } 50 | }) 51 | 52 | const authenticate = async (Username, Password) => 53 | await new Promise((resolve, reject) => { 54 | const user = new CognitoUser({ Username, Pool }) 55 | const authDetails = new AuthenticationDetails({ Username, Password }) 56 | 57 | user.authenticateUser(authDetails, { 58 | onSuccess: (data) => { 59 | console.log('onSuccess:', data) 60 | resolve(data) 61 | }, 62 | 63 | onFailure: (err) => { 64 | console.error('onFailure:', err) 65 | reject(err) 66 | }, 67 | 68 | newPasswordRequired: (data) => { 69 | console.log('newPasswordRequired:', data) 70 | resolve(data) 71 | }, 72 | }) 73 | }) 74 | 75 | const logout = () => { 76 | const user = Pool.getCurrentUser() 77 | if (user) { 78 | user.signOut() 79 | } 80 | } 81 | 82 | return ( 83 | 90 | {props.children} 91 | 92 | ) 93 | } 94 | 95 | export { Account, AccountContext } 96 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from 'react' 2 | import AWS from 'aws-sdk' 3 | import { CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js' 4 | import Pool from '../UserPool' 5 | 6 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 7 | const AccountContext = createContext() 8 | 9 | const Account = (props) => { 10 | const getSession = async () => 11 | await new Promise((resolve, reject) => { 12 | const user = Pool.getCurrentUser() 13 | if (user) { 14 | user.getSession(async (err, session) => { 15 | if (err) { 16 | reject() 17 | } else { 18 | const attributes = await new Promise((resolve, reject) => { 19 | user.getUserAttributes((err, attributes) => { 20 | if (err) { 21 | reject(err) 22 | } else { 23 | console.log('attributes:', attributes) 24 | const results = {} 25 | 26 | for (let attribute of attributes) { 27 | const { Name, Value } = attribute 28 | results[Name] = Value 29 | } 30 | 31 | resolve(results) 32 | } 33 | }) 34 | }) 35 | 36 | const accessToken = session.accessToken.jwtToken 37 | 38 | const mfaEnabled = await new Promise((resolve) => { 39 | cognito.getUser( 40 | { 41 | AccessToken: accessToken, 42 | }, 43 | (err, data) => { 44 | if (err) resolve(false) 45 | else 46 | resolve( 47 | data.UserMFASettingList && 48 | data.UserMFASettingList.includes('SOFTWARE_TOKEN_MFA') 49 | ) 50 | } 51 | ) 52 | }) 53 | 54 | const token = session.getIdToken().getJwtToken() 55 | 56 | resolve({ 57 | user, 58 | accessToken, 59 | mfaEnabled, 60 | headers: { 61 | 'x-api-key': attributes['custom:apikey'], 62 | Authorization: token, 63 | }, 64 | ...session, 65 | ...attributes, 66 | }) 67 | } 68 | }) 69 | } else { 70 | reject() 71 | } 72 | }) 73 | 74 | const authenticate = async (Username, Password) => 75 | await new Promise((resolve, reject) => { 76 | const user = new CognitoUser({ Username, Pool }) 77 | const authDetails = new AuthenticationDetails({ Username, Password }) 78 | 79 | user.authenticateUser(authDetails, { 80 | onSuccess: (data) => { 81 | console.log('onSuccess:', data) 82 | resolve(data) 83 | }, 84 | 85 | onFailure: (err) => { 86 | console.error('onFailure:', err) 87 | reject(err) 88 | }, 89 | 90 | newPasswordRequired: (data) => { 91 | console.log('newPasswordRequired:', data) 92 | resolve(data) 93 | }, 94 | 95 | totpRequired: () => { 96 | const token = prompt('Please enter your 6-digit token') 97 | user.sendMFACode( 98 | token, 99 | { 100 | onSuccess: () => (window.location.href = window.location.href), 101 | onFailure: () => alert('Incorrect code!'), 102 | }, 103 | 'SOFTWARE_TOKEN_MFA' 104 | ) 105 | }, 106 | }) 107 | }) 108 | 109 | const logout = () => { 110 | const user = Pool.getCurrentUser() 111 | if (user) { 112 | user.signOut() 113 | } 114 | } 115 | 116 | return ( 117 | 124 | {props.children} 125 | 126 | ) 127 | } 128 | 129 | export { Account, AccountContext } 130 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/Accounts.js: -------------------------------------------------------------------------------- 1 | import React, { createContext } from 'react' 2 | import AWS from 'aws-sdk' 3 | import { CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js' 4 | import Pool from '../UserPool' 5 | 6 | const cognito = new AWS.CognitoIdentityServiceProvider({ region: 'us-east-1' }) 7 | const AccountContext = createContext() 8 | 9 | const Account = (props) => { 10 | const getSession = async () => 11 | await new Promise((resolve, reject) => { 12 | const user = Pool.getCurrentUser() 13 | if (user) { 14 | user.getSession(async (err, session) => { 15 | if (err) { 16 | reject() 17 | } else { 18 | const attributes = await new Promise((resolve, reject) => { 19 | user.getUserAttributes((err, attributes) => { 20 | if (err) { 21 | reject(err) 22 | } else { 23 | console.log('attributes:', attributes) 24 | const results = {} 25 | 26 | for (let attribute of attributes) { 27 | const { Name, Value } = attribute 28 | results[Name] = Value 29 | } 30 | 31 | resolve(results) 32 | } 33 | }) 34 | }) 35 | 36 | const accessToken = session.accessToken.jwtToken 37 | 38 | const mfaEnabled = await new Promise((resolve) => { 39 | cognito.getUser( 40 | { 41 | AccessToken: accessToken, 42 | }, 43 | (err, data) => { 44 | if (err) resolve(false) 45 | else 46 | resolve( 47 | data.UserMFASettingList && 48 | data.UserMFASettingList.includes('SOFTWARE_TOKEN_MFA') 49 | ) 50 | } 51 | ) 52 | }) 53 | 54 | const token = session.getIdToken().getJwtToken() 55 | 56 | resolve({ 57 | user, 58 | accessToken, 59 | mfaEnabled, 60 | headers: { 61 | 'x-api-key': attributes['custom:apikey'], 62 | Authorization: token, 63 | }, 64 | ...session, 65 | ...attributes, 66 | }) 67 | } 68 | }) 69 | } else { 70 | reject() 71 | } 72 | }) 73 | 74 | const authenticate = async (Username, Password) => 75 | await new Promise((resolve, reject) => { 76 | const user = new CognitoUser({ Username, Pool }) 77 | const authDetails = new AuthenticationDetails({ Username, Password }) 78 | 79 | user.authenticateUser(authDetails, { 80 | onSuccess: (data) => { 81 | console.log('onSuccess:', data) 82 | resolve(data) 83 | }, 84 | 85 | onFailure: (err) => { 86 | console.error('onFailure:', err) 87 | reject(err) 88 | }, 89 | 90 | newPasswordRequired: (data) => { 91 | console.log('newPasswordRequired:', data) 92 | resolve(data) 93 | }, 94 | 95 | totpRequired: () => { 96 | const token = prompt('Please enter your 6-digit token') 97 | user.sendMFACode( 98 | token, 99 | { 100 | onSuccess: () => (window.location.href = window.location.href), 101 | onFailure: () => alert('Incorrect code!'), 102 | }, 103 | 'SOFTWARE_TOKEN_MFA' 104 | ) 105 | }, 106 | }) 107 | }) 108 | 109 | const logout = () => { 110 | const user = Pool.getCurrentUser() 111 | if (user) { 112 | user.signOut() 113 | } 114 | } 115 | 116 | return ( 117 | 124 | {props.children} 125 | 126 | ) 127 | } 128 | 129 | export { Account, AccountContext } 130 | -------------------------------------------------------------------------------- /10-TOTP-MFA/src/components/MFA.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState, useContext } from 'react' 2 | import { AccountContext } from './Accounts' 3 | 4 | export default () => { 5 | const [userCode, setUserCode] = useState('') 6 | const [enabled, setEnabled] = useState(false) 7 | const [image, setImage] = useState('') 8 | 9 | const { getSession } = useContext(AccountContext) 10 | 11 | useEffect(() => { 12 | getSession().then(({ mfaEnabled }) => { 13 | setEnabled(mfaEnabled) 14 | }) 15 | }, []) 16 | 17 | const API = 'https://yn452m1sf4.execute-api.us-east-1.amazonaws.com/dev/mfa' 18 | 19 | const getQRCode = () => { 20 | getSession().then(({ accessToken, headers }) => { 21 | if (typeof accessToken !== 'string') { 22 | accessToken = accessToken.jwtToken 23 | } 24 | 25 | const uri = `${API}?accessToken=${accessToken}` 26 | console.log(uri) 27 | 28 | fetch(uri, { 29 | headers, 30 | }) 31 | .then((data) => data.json()) 32 | .then(setImage) 33 | .catch(console.error) 34 | }) 35 | } 36 | 37 | const enableMFA = (event) => { 38 | event.preventDefault() 39 | 40 | console.log('USER CODE:', userCode) 41 | 42 | getSession().then(({ user, accessToken, headers }) => { 43 | if (typeof accessToken !== 'string') { 44 | accessToken = accessToken.jwtToken 45 | } 46 | 47 | const uri = `${API}?accessToken=${accessToken}&userCode=${userCode}` 48 | console.log(uri) 49 | 50 | fetch(uri, { 51 | method: 'POST', 52 | headers, 53 | }) 54 | .then((data) => data.json()) 55 | .then((result) => { 56 | if (result.Status && result.Status === 'SUCCESS') { 57 | setEnabled(true) 58 | 59 | const settings = { 60 | PreferredMfa: true, 61 | Enabled: true, 62 | } 63 | 64 | user.setUserMfaPreference(null, settings, () => {}) 65 | } else { 66 | console.log(result) 67 | 68 | if (result.errorType === 'EnableSoftwareTokenMFAException') { 69 | alert('Incorrect 6-digit code!') 70 | } else if (result.errorType === 'InvalidParameterException') { 71 | alert('Please provide a 6-digit number') 72 | } 73 | } 74 | }) 75 | .catch(console.error) 76 | }) 77 | } 78 | 79 | const disableMFA = (event) => { 80 | event.preventDefault() 81 | 82 | getSession().then(({ headers, accessToken }) => { 83 | if (typeof accessToken !== 'string') { 84 | accessToken = accessToken.jwtToken 85 | } 86 | 87 | const uri = `${API}?accessToken=${accessToken}&userCode=${userCode}` 88 | console.log(uri) 89 | 90 | fetch(uri, { 91 | method: 'DELETE', 92 | headers, 93 | }) 94 | .then((data) => data.json()) 95 | .then(console.log) 96 | .catch(console.error) 97 | }) 98 | } 99 | 100 | return ( 101 |
102 |

Multi-Factor Authentication

103 | 104 | {enabled ? ( 105 |
106 |
MFA is enabled
107 | 108 |
109 | setUserCode(event.target.value)} 112 | required 113 | /> 114 | 115 | 116 |
117 |
118 | ) : image ? ( 119 |
120 |

Scan this QR code:

121 | 122 | 123 |
124 | setUserCode(event.target.value)} 127 | required 128 | /> 129 | 130 | 131 |
132 |
133 | ) : ( 134 | 135 | )} 136 |
137 | ) 138 | } 139 | -------------------------------------------------------------------------------- /11-Delete-Users/src/components/MFA.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState, useContext } from 'react' 2 | import { AccountContext } from './Accounts' 3 | 4 | export default () => { 5 | const [userCode, setUserCode] = useState('') 6 | const [enabled, setEnabled] = useState(false) 7 | const [image, setImage] = useState('') 8 | 9 | const { getSession } = useContext(AccountContext) 10 | 11 | useEffect(() => { 12 | getSession().then(({ mfaEnabled }) => { 13 | setEnabled(mfaEnabled) 14 | }) 15 | }, []) 16 | 17 | const API = 'https://yn452m1sf4.execute-api.us-east-1.amazonaws.com/dev/mfa' 18 | 19 | const getQRCode = () => { 20 | getSession().then(({ accessToken, headers }) => { 21 | if (typeof accessToken !== 'string') { 22 | accessToken = accessToken.jwtToken 23 | } 24 | 25 | const uri = `${API}?accessToken=${accessToken}` 26 | console.log(uri) 27 | 28 | fetch(uri, { 29 | headers, 30 | }) 31 | .then((data) => data.json()) 32 | .then(setImage) 33 | .catch(console.error) 34 | }) 35 | } 36 | 37 | const enableMFA = (event) => { 38 | event.preventDefault() 39 | 40 | console.log('USER CODE:', userCode) 41 | 42 | getSession().then(({ user, accessToken, headers }) => { 43 | if (typeof accessToken !== 'string') { 44 | accessToken = accessToken.jwtToken 45 | } 46 | 47 | const uri = `${API}?accessToken=${accessToken}&userCode=${userCode}` 48 | console.log(uri) 49 | 50 | fetch(uri, { 51 | method: 'POST', 52 | headers, 53 | }) 54 | .then((data) => data.json()) 55 | .then((result) => { 56 | if (result.Status && result.Status === 'SUCCESS') { 57 | setEnabled(true) 58 | 59 | const settings = { 60 | PreferredMfa: true, 61 | Enabled: true, 62 | } 63 | 64 | user.setUserMfaPreference(null, settings, () => {}) 65 | } else { 66 | console.log(result) 67 | 68 | if (result.errorType === 'EnableSoftwareTokenMFAException') { 69 | alert('Incorrect 6-digit code!') 70 | } else if (result.errorType === 'InvalidParameterException') { 71 | alert('Please provide a 6-digit number') 72 | } 73 | } 74 | }) 75 | .catch(console.error) 76 | }) 77 | } 78 | 79 | const disableMFA = (event) => { 80 | event.preventDefault() 81 | 82 | getSession().then(({ headers, accessToken }) => { 83 | if (typeof accessToken !== 'string') { 84 | accessToken = accessToken.jwtToken 85 | } 86 | 87 | const uri = `${API}?accessToken=${accessToken}&userCode=${userCode}` 88 | console.log(uri) 89 | 90 | fetch(uri, { 91 | method: 'DELETE', 92 | headers, 93 | }) 94 | .then((data) => data.json()) 95 | .then(console.log) 96 | .catch(console.error) 97 | }) 98 | } 99 | 100 | return ( 101 |
102 |

Multi-Factor Authentication

103 | 104 | {enabled ? ( 105 |
106 |
MFA is enabled
107 | 108 |
109 | setUserCode(event.target.value)} 112 | required 113 | /> 114 | 115 | 116 |
117 |
118 | ) : image ? ( 119 |
120 |

Scan this QR code:

121 | 122 | 123 |
124 | setUserCode(event.target.value)} 127 | required 128 | /> 129 | 130 | 131 |
132 |
133 | ) : ( 134 | 135 | )} 136 |
137 | ) 138 | } 139 | --------------------------------------------------------------------------------