Skip to content

Enable the Dev Portal to use an existing Cognito User Pool #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions cloudformation/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Parameters:
Type: String
Description: The Domain Name (or Prefix) at which your Cognito Hosted UI is located. This should be regionally unique.

ExistingCognitoUserPool:
Type: String
Description: The existing User Pool ID. Leave blank to create a new User Pool.

# CognitoDomainAcmCertArn:
# Type: String
# Description: Doesn't yet do anything. Oh well.
Expand Down Expand Up @@ -134,6 +138,7 @@ Conditions:
DevelopmentMode: !Equals [!Ref DevelopmentMode, 'true']
NotDevelopmentMode: !Not [!Condition DevelopmentMode]
InUSEastOne: !Equals [!Ref 'AWS::Region', 'us-east-1']
CreateCognitoUserPool: !Equals [!Ref ExistingCognitoUserPool, '']

Resources:
ApiGatewayApi:
Expand Down Expand Up @@ -564,6 +569,7 @@ Resources:
arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity
${CloudFrontOriginAccessIdentity}


ArtifactsS3Bucket:
Type: AWS::S3::Bucket
Properties:
Expand Down Expand Up @@ -960,7 +966,7 @@ Resources:
- ':'
- !Ref 'AWS::AccountId'
- ':userpool/'
- !Ref CognitoUserPool
- !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool]

LambdaSNSExecutionPermission:
Type: AWS::Lambda::Permission
Expand Down Expand Up @@ -1043,6 +1049,7 @@ Resources:

CognitoUserPool:
Type: AWS::Cognito::UserPool
Condition: CreateCognitoUserPool
Properties:
UserPoolName: !Ref CognitoIdentityPoolName
LambdaConfig:
Expand All @@ -1064,7 +1071,7 @@ Resources:
# However, when this is updated and changes, the CUPCS custom resource doesn't re-run, and so a bunch of vital
# settings won't be set, e.g., CallbackURL.
Properties:
UserPoolId: !Ref CognitoUserPool
UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool]
ClientName: CognitoIdentityPool
GenerateSecret: false
RefreshTokenValidity: 30
Expand Down Expand Up @@ -1116,7 +1123,7 @@ Resources:
Properties:
Timeout: 360
ServiceToken: !GetAtt CognitoUserPoolClientSettingsBackingFn.Arn
UserPoolId: !Ref CognitoUserPool
UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool]
UserPoolClientId: !Ref CognitoUserPoolClient
SupportedIdentityProviders: [ "COGNITO" ] # should (eventually) allow people to add values
CallbackURL: !If [ DevelopmentMode,
Expand Down Expand Up @@ -1193,6 +1200,7 @@ Resources:

CognitoUserPoolDomain:
Type: AWS::CloudFormation::CustomResource
Condition: CreateCognitoUserPool
Properties:
Timeout: 360
ServiceToken: !GetAtt CognitoUserPoolDomainBackingFn.Arn
Expand All @@ -1211,7 +1219,7 @@ Resources:
- - cognito-idp.
- !Ref 'AWS::Region'
- .amazonaws.com/
- !Ref CognitoUserPool
- !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool]

CognitoIdentityPoolRoles:
Type: AWS::Cognito::IdentityPoolRoleAttachment
Expand Down Expand Up @@ -1308,7 +1316,7 @@ Resources:
# since admin group has a precedence of 0, it takes priority
Precedence: 0
RoleArn: !GetAtt CognitoAdminRole.Arn
UserPoolId: !Ref CognitoUserPool
UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool]

CatalogUpdaterLambdaFunction:
Type: AWS::Serverless::Function
Expand Down Expand Up @@ -1354,9 +1362,9 @@ Resources:
RestApiId: !Ref ApiGatewayApi
Region: !Ref 'AWS::Region'
IdentityPoolId: !Ref CognitoIdentityPool
UserPoolId: !Ref CognitoUserPool
UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool]
UserPoolClientId: !Ref CognitoUserPoolClient
UserPoolDomain: !GetAtt CognitoUserPoolDomain.FullUrl
UserPoolDomain: !If [ CreateCognitoUserPool, !GetAtt CognitoUserPoolDomain.FullUrl, !Ref CognitoDomainNameOrPrefix ]
MarketplaceSuffix: !Ref MarketplaceSubscriptionTopicProductCode
RebuildToken: !Ref StaticAssetRebuildToken
RebuildMode: !Ref StaticAssetRebuildMode
Expand Down
6 changes: 5 additions & 1 deletion dev-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ module.exports = {
// Change the name of the customer's table. Useful for multiple stacks. Defaults to `DevPortalCustomers`
// customersTableName: `DevPortalCustomers`,

// Optional Existing Cognito User Pool. This parameter alters the value of the CognitoDomainName value. See below.
// cognitoUserPool: "eu-west-1_XXX",

// Turns on cognito hosted sign in / sign up UI; Defaults to `` (blank string)
// Important: If 'cognitoUserPool' is provided, this needs to be the full URL of the Cognito hosted UI (e.g. https://my.auth.org or https://myauth.auth.eu-west-1.amazoncognito.com)
// cognitoDomainName: `auth-url`,

// Set this to overwrite-content if you want to reset your custom content back to the defaults. Defaults to ``
// staticAssetRebuildMode: `overwrite-content` // ONLY SET

Expand Down
6 changes: 5 additions & 1 deletion dev-portal/scripts/deploy-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ const staticAssetRebuildMode = deployerConfig.staticAssetRebuildMode || ''
const awsSamCliProfile = deployerConfig.awsSamCliProfile;
const profileOption = awsSamCliProfile ? `--profile ${awsSamCliProfile}` : ''

// Existing Cognito User Pool configuration
const existingCognitoUserPool = deployerConfig.cognitoUserPool || "";


function main() {
Promise.resolve()
.then(() => execute(`sam package --template-file ${samTemplate} --output-template-file ${packageConfig} --s3-bucket ${buildAssetsBucket} ${profileOption}`, true))
.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket} ${profileOption}`, true))
.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides ExistingCognitoUserPool="${existingCognitoUserPool}" StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket} ${profileOption}`, true))
.then(() => writeConfig(true))
.then(() => console.log('\n' + 'Process Complete! Run `npm run start` to launch run the dev portal locally.\n'.green()))
.catch(err => {
Expand Down
10 changes: 5 additions & 5 deletions lambdas/static-asset-uploader/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.4ae54ac6.chunk.css",
"main.js": "/static/js/main.7266b749.chunk.js",
"main.js.map": "/static/js/main.7266b749.chunk.js.map",
"main.js": "/static/js/main.ccbe5721.chunk.js",
"main.js.map": "/static/js/main.ccbe5721.chunk.js.map",
"runtime~main.js": "/static/js/runtime~main.a8a9905a.js",
"runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map",
"static/css/2.1eb883ec.chunk.css": "/static/css/2.1eb883ec.chunk.css",
"static/js/2.a41b16cf.chunk.js": "/static/js/2.a41b16cf.chunk.js",
"static/js/2.a41b16cf.chunk.js.map": "/static/js/2.a41b16cf.chunk.js.map",
"static/js/2.6001b07b.chunk.js": "/static/js/2.6001b07b.chunk.js",
"static/js/2.6001b07b.chunk.js.map": "/static/js/2.6001b07b.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.a34f6f07da0e4c9969330f1c0db2bbca.js": "/precache-manifest.a34f6f07da0e4c9969330f1c0db2bbca.js",
"precache-manifest.5cead564eb6cd8571ee73903a5f485a0.js": "/precache-manifest.5cead564eb6cd8571ee73903a5f485a0.js",
"service-worker.js": "/service-worker.js",
"static/css/2.1eb883ec.chunk.css.map": "/static/css/2.1eb883ec.chunk.css.map",
"static/css/main.4ae54ac6.chunk.css.map": "/static/css/main.4ae54ac6.chunk.css.map",
Expand Down
2 changes: 1 addition & 1 deletion lambdas/static-asset-uploader/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="shortcut icon" href="/custom-content/favicon.ico"><script type="text/javascript" src="/config.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/axios/dist/axios.standalone.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/rollups/hmac-sha256.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/rollups/sha256.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/components/hmac.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/components/enc-base64.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/url-template/url-template.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/sigV4Client.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/apiGatewayClient.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/simpleHttpClient.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/utils.js"></script><script type="text/javascript" src="/apigateway-js-sdk/apigClient.js"></script><link rel="stylesheet" href="/custom-content/styles.css"><title>Developer Portal</title><link href="/static/css/2.1eb883ec.chunk.css" rel="stylesheet"><link href="/static/css/main.4ae54ac6.chunk.css" rel="stylesheet"></head><body><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="/static/js/2.a41b16cf.chunk.js"></script><script src="/static/js/main.7266b749.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="shortcut icon" href="/custom-content/favicon.ico"><script type="text/javascript" src="/config.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/axios/dist/axios.standalone.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/rollups/hmac-sha256.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/rollups/sha256.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/components/hmac.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/CryptoJS/components/enc-base64.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/url-template/url-template.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/sigV4Client.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/apiGatewayClient.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/simpleHttpClient.js"></script><script type="text/javascript" src="/apigateway-js-sdk/lib/apiGatewayCore/utils.js"></script><script type="text/javascript" src="/apigateway-js-sdk/apigClient.js"></script><link rel="stylesheet" href="/custom-content/styles.css"><title>Developer Portal</title><link href="/static/css/2.1eb883ec.chunk.css" rel="stylesheet"><link href="/static/css/main.4ae54ac6.chunk.css" rel="stylesheet"></head><body><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="/static/js/2.6001b07b.chunk.js"></script><script src="/static/js/main.ccbe5721.chunk.js"></script></body></html>
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "b3b3162a6d603761379a2f8d4f2e010a",
"revision": "db59ca4c085e3abac60aa6911cd56474",
"url": "/index.html"
},
{
"revision": "f4c138290295f841f5c2",
"revision": "48ec5258c5fc3ac61c33",
"url": "/static/css/2.1eb883ec.chunk.css"
},
{
"revision": "4c4f98db8ced0c0fb3d7",
"revision": "8e0728ada42ae2598aef",
"url": "/static/css/main.4ae54ac6.chunk.css"
},
{
"revision": "f4c138290295f841f5c2",
"url": "/static/js/2.a41b16cf.chunk.js"
"revision": "48ec5258c5fc3ac61c33",
"url": "/static/js/2.6001b07b.chunk.js"
},
{
"revision": "4c4f98db8ced0c0fb3d7",
"url": "/static/js/main.7266b749.chunk.js"
"revision": "8e0728ada42ae2598aef",
"url": "/static/js/main.ccbe5721.chunk.js"
},
{
"revision": "42ac5946195a7306e2a5",
Expand Down
2 changes: 1 addition & 1 deletion lambdas/static-asset-uploader/build/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");

importScripts(
"/precache-manifest.a34f6f07da0e4c9969330f1c0db2bbca.js"
"/precache-manifest.5cead564eb6cd8571ee73903a5f485a0.js"
);

self.addEventListener('message', (event) => {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.