From 6d5fd99985f0666ec8030b1f22135a1131e591e9 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Mon, 2 Mar 2020 15:37:45 -0800 Subject: [PATCH] Added null or empty check for IdentityUrlExternal --- deploy/aro/identity-api/azure-pipelines.yml | 2 +- .../aro/identity-api/identityapi-deploy-template.yml | 6 ++++++ src/Services/Identity/Identity.API/Startup.cs | 12 ++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/deploy/aro/identity-api/azure-pipelines.yml b/deploy/aro/identity-api/azure-pipelines.yml index 1f305c059..b8084e1df 100644 --- a/deploy/aro/identity-api/azure-pipelines.yml +++ b/deploy/aro/identity-api/azure-pipelines.yml @@ -40,7 +40,7 @@ stages: - script: 'oc project $(OpenShiftProject)' failOnStderr: true displayName: 'Set OpenShift Project Context' - - script: 'oc process -f ./deploy/aro/identity-api/identityapi-deploy-template.yml -p IMAGE_REGISTRY_PROJECT_NAME=$(SourceImageRegistryProjectName) -p WEB_SPA_URL=$(WebSpaUrl) -p WEB_MVC_URL=$(WebMvcUrl) -p LOCATION_API_URL=$(LocationsApiUrl) -p MARKETING_API_URL=$(MarketingApiUrl) -p BASKET_API_URL=$(BasketApiUrl) -p ORDERING_API_URL=$(OrderingApiUrl) -p MOBILE_SHOPPING_AGGREGATOR_URL=$(MobileShoppingAggregatorUrl) -p WEB_SHOPPING_AGGREGATOR_URL=$(WebShoppingAggregatorUrl) -p WEBHOOKS_API_URL=$(WebhooksApiUrl) -p WEBHOOKS_WEB_CLIENT_URL=$(WebhooksWebClientUrl) | oc apply -f-' + - script: 'oc process -f ./deploy/aro/identity-api/identityapi-deploy-template.yml -p IMAGE_REGISTRY_PROJECT_NAME=$(SourceImageRegistryProjectName) -p IDENTITY_URL_EXTERNAL=$(IdentityUrlExternal) -p WEB_SPA_URL=$(WebSpaUrl) -p WEB_MVC_URL=$(WebMvcUrl) -p LOCATION_API_URL=$(LocationsApiUrl) -p MARKETING_API_URL=$(MarketingApiUrl) -p BASKET_API_URL=$(BasketApiUrl) -p ORDERING_API_URL=$(OrderingApiUrl) -p MOBILE_SHOPPING_AGGREGATOR_URL=$(MobileShoppingAggregatorUrl) -p WEB_SHOPPING_AGGREGATOR_URL=$(WebShoppingAggregatorUrl) -p WEBHOOKS_API_URL=$(WebhooksApiUrl) -p WEBHOOKS_WEB_CLIENT_URL=$(WebhooksWebClientUrl) | oc apply -f-' failOnStderr: true displayName: 'Ensure Identity API OpenShift DeploymentConfig and Service' - script: 'oc apply -f ./deploy/aro/identity-api/identity-public-route.json' diff --git a/deploy/aro/identity-api/identityapi-deploy-template.yml b/deploy/aro/identity-api/identityapi-deploy-template.yml index 15c665bc3..a32b229f3 100644 --- a/deploy/aro/identity-api/identityapi-deploy-template.yml +++ b/deploy/aro/identity-api/identityapi-deploy-template.yml @@ -26,6 +26,8 @@ objects: spec: containers: - env: + - name: IdentityUrlExternal + value: ${IDENTITY_URL_EXTERNAL} - name: SpaClient value: ${WEB_SPA_URL} - name: XamarinCallback @@ -113,6 +115,10 @@ parameters: name: TEMPLATE_NAME required: true value: identityapi-deploy-template +- description: The external URL of the Identity endpoint + displayName: Identity URL External + name: IDENTITY_URL_EXTERNAL + required: true - description: The cluster internal URL of the Web SPA endpoint displayName: Web SPA URL name: WEB_SPA_URL diff --git a/src/Services/Identity/Identity.API/Startup.cs b/src/Services/Identity/Identity.API/Startup.cs index a9e0726bc..72d335815 100644 --- a/src/Services/Identity/Identity.API/Startup.cs +++ b/src/Services/Identity/Identity.API/Startup.cs @@ -76,9 +76,13 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; // Check to see if the Identity server is using https - var identityUrl = this.Configuration.GetValue("IdentityUrl"); - var identityUri = new Uri(identityUrl); - var isUsingHttps = identityUri.Scheme == Uri.UriSchemeHttps; + var isUsingHttps = false; + var identityUrlExternal = this.Configuration.GetValue("IdentityUrlExternal"); + if (!string.IsNullOrEmpty(identityUrlExternal)) + { + var identityUri = new Uri(identityUrlExternal); + isUsingHttps = identityUri.Scheme == Uri.UriSchemeHttps; + } // Adds IdentityServer services.AddIdentityServer(x => @@ -89,7 +93,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API // Need this if using https if (isUsingHttps) { - x.PublicOrigin = identityUrl; + x.PublicOrigin = identityUrlExternal; } }) .AddDevspacesIfNeeded(Configuration.GetValue("EnableDevspaces", false))