Skip to content

Commit

Permalink
feat(amplify-category-auth): add HostedUI custom domain in metadata
Browse files Browse the repository at this point in the history
HostedUIDomain equals to either the domain prefix or the custom domain defined in the user pool.
However we need to differentiate a custom domain from a domain prefix for the config put in
aws-exports.js

fix aws-amplify#1880
  • Loading branch information
vic-blt committed Jan 28, 2021
1 parent 39dfd27 commit a21f00e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ const createMetaOutput = (answers: ImportAnswers, hasOAuthConfig: boolean): Meta
...(answers.appClientNative!.ClientSecret ? { AppClientSecret: answers.appClientNative!.ClientSecret } : {}),
AppClientIDWeb: answers.appClientWeb!.ClientId,
HostedUIDomain: userPool.Domain,
HostedUICustomDomain: userPool.CustomDomain,
};

if (answers.authSelections === 'identityPoolAndUserPool') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type MetaOutput = {
FacebookWebClient?: string;
GoogleWebClient?: string;
HostedUIDomain?: string;
HostedUICustomDomain?: string;
OAuthMetadata?: string;
CreatedSNSRole?: string;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-e2e-tests/src/import-helpers/expects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const expectAuthProjectDetailsMatch = (projectDetails: AuthProjectDetails
expect(projectDetails.meta.AppClientID).toEqual(ogProjectDetails.meta.AppClientID);
expect(projectDetails.meta.AppClientIDWeb).toEqual(ogProjectDetails.meta.AppClientIDWeb);
expect(projectDetails.meta.HostedUIDomain).toEqual(ogProjectDetails.meta.HostedUIDomain);
expect(projectDetails.meta.HostedUICustomDomain).toEqual(ogProjectDetails.meta.HostedUICustomDomain);

if (projectDetails.meta.OAuthMetadata) {
expect(ogProjectDetails.meta.OAuthMetadata).toBeDefined();
Expand Down Expand Up @@ -48,6 +49,7 @@ export const expectAuthLocalAndOGMetaFilesOutputMatching = (projectRoot: string,
expect(authMeta.output.AppClientID).toEqual(ogAuthMeta.output.AppClientID);
expect(authMeta.output.AppClientIDWeb).toEqual(ogAuthMeta.output.AppClientIDWeb);
expect(authMeta.output.HostedUIDomain).toEqual(ogAuthMeta.output.HostedUIDomain);
expect(authMeta.output.HostedUICustomDomain).toEqual(ogAuthMeta.output.HostedUICustomDomain);
expect(authMeta.output.UserPoolId).toEqual(ogAuthMeta.output.UserPoolId);
};

Expand Down
1 change: 1 addition & 0 deletions packages/amplify-e2e-tests/src/import-helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type AuthProjectDetails = {
AppClientSecret?: string;
AppClientIDWeb?: string;
HostedUIDomain?: string;
HostedUICustomDomain?: string;
OAuthMetadata?: $TSObject;
IdentityPoolId?: string;
IdentityPoolName?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-e2e-tests/src/import-helpers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const getAuthProjectDetails = (projectRoot: string): AuthProjectDetails =
AppClientSecret: authMeta.output.AppClientSecret,
AppClientIDWeb: authMeta.output.AppClientIDWeb,
HostedUIDomain: authMeta.output.HostedUIDomain,
HostedUICustomDomain: authMeta.output.HostedUICustomDomain,
OAuthMetadata: authMeta.output.OAuthMetadata ? JSON.parse(authMeta.output.OAuthMetadata) : undefined,
},
team: {
Expand Down Expand Up @@ -105,6 +106,7 @@ export const getOGAuthProjectDetails = (projectRoot: string): AuthProjectDetails
AppClientSecret: authMeta.output.AppClientSecret,
AppClientIDWeb: authMeta.output.AppClientIDWeb,
HostedUIDomain: authMeta.output.HostedUIDomain,
HostedUICustomDomain: authMeta.output.HostedUICustomDomain,
OAuthMetadata: authMeta.output.OAuthMetadata ? JSON.parse(authMeta.output.OAuthMetadata) : undefined,
},
team: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
let redirectSignOut;

if (cognitoResource.output.HostedUIDomain) {
domain = `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
domain =
cognitoResource.output.HostedUICustomDomain || `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
}

if (cognitoResource.output.OAuthMetadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
let redirectSignOut;

if (cognitoResource.output.HostedUIDomain) {
domain = `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
domain =
cognitoResource.output.HostedUICustomDomain || `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
}

if (cognitoResource.output.OAuthMetadata) {
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-frontend-ios/lib/frontend-config-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
let redirectSignOut;

if (cognitoResource.output.HostedUIDomain) {
domain = `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
domain =
cognitoResource.output.HostedUICustomDomain || `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
}

if (cognitoResource.output.OAuthMetadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
let federationTarget;

if (cognitoResource.output.HostedUIDomain) {
domain = `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
domain =
cognitoResource.output.HostedUICustomDomain || `${cognitoResource.output.HostedUIDomain}.auth.${projectRegion}.amazoncognito.com`;
}
if (cognitoResource.output.OAuthMetadata) {
const oAuthMetadata = JSON.parse(cognitoResource.output.OAuthMetadata);
Expand Down Expand Up @@ -339,7 +340,8 @@ function getAPIGWConfig(apigwResources, projectRegion, configOutput) {
};

for (let i = 0; i < apigwResources.length; i += 1) {
if (apigwResources[i].output.ApiName && apigwResources[i].output.RootUrl) { // only REST endpoints contains this information
if (apigwResources[i].output.ApiName && apigwResources[i].output.RootUrl) {
// only REST endpoints contains this information
apigwConfig.aws_cloud_logic_custom.push({
name: apigwResources[i].output.ApiName,
endpoint: apigwResources[i].output.RootUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ function showRestAPIURL(context, resourcesToBeCreated) {
}

function showContainerHostingInfo(context, resourcesToBeCreated) {
const resource = resourcesToBeCreated.find(resource => resource.category === 'hosting' && resource.service === 'ElasticContainer' && !resource.hostedZoneId);
const resource = resourcesToBeCreated.find(
resource => resource.category === 'hosting' && resource.service === 'ElasticContainer' && !resource.hostedZoneId,
);
if (resource && resource.output) {
const {
output: {
LoadBalancerCnameDomainName,
LoadBalancerAliasDomainName,
CloudfrontDistributionAliasDomainName,
CloudfrontDistributionCnameDomainName
}
CloudfrontDistributionCnameDomainName,
},
} = resource;

context.print.info(`Make sure to add the following CNAMEs to your domain’s DNS records:\n`);
Expand Down Expand Up @@ -143,19 +145,23 @@ function showHostedUIURLs(context, resourcesToBeCreated) {
}
const { Region } = amplifyMeta.providers.awscloudformation;

const { HostedUIDomain, AppClientIDWeb, OAuthMetadata } = amplifyMeta[category][resourceName].output;
const { HostedUIDomain, HostedUICustomDomain, AppClientIDWeb, OAuthMetadata } = amplifyMeta[category][resourceName].output;

if (OAuthMetadata) {
const oAuthMetadata = JSON.parse(OAuthMetadata);
const hostedUIEndpoint = `https://${HostedUIDomain}.auth.${Region}.amazoncognito.com/`;
const hostedUIEndpoint = HostedUICustomDomain
? `https://${HostedUICustomDomain}`
: `https://${HostedUIDomain}.auth.${Region}.amazoncognito.com/`;
context.print.info(chalk`Hosted UI Endpoint: {blue.underline ${hostedUIEndpoint}}`);
const redirectURIs = oAuthMetadata.CallbackURLs.concat(oAuthMetadata.LogoutURLs);
if (redirectURIs.length > 0) {
const [responseType] = oAuthMetadata.AllowedOAuthFlows;

const testHostedUIEndpoint = `https://${HostedUIDomain}.auth.${Region}.amazoncognito.com/login?response_type=${
responseType === 'implicit' ? 'token' : 'code'
}&client_id=${AppClientIDWeb}&redirect_uri=${redirectURIs[0]}\n`;
const testHostedUIEndpoint =
(HostedUICustomDomain ? `https://${HostedUICustomDomain}` : `https://${HostedUIDomain}.auth.${Region}.amazoncognito.com`) +
`/login?response_type=${responseType === 'implicit' ? 'token' : 'code'}&client_id=${AppClientIDWeb}&redirect_uri=${
redirectURIs[0]
}\n`;
context.print.info(chalk`Test Your Hosted UI Endpoint: {blue.underline ${testHostedUIEndpoint}}`);
}
}
Expand Down

0 comments on commit a21f00e

Please sign in to comment.