From 048c2cb1a8eac65d344edd7d5f18397afbb219bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 3 Aug 2021 12:10:26 +0300 Subject: [PATCH] Added host names and updated the certificate code --- .../eventhub/charts/api/templates/api.yaml | 8 ++++- .../EventHubIdentityServerModule.cs | 35 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml b/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml index b5ad403..8a40a70 100644 --- a/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml +++ b/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml @@ -19,4 +19,10 @@ spec: - name: apihttp containerPort: 80 - name: apihttps - containerPort: 443 \ No newline at end of file + containerPort: 443 + hostAliases: + - ip: 10.105.172.183 + hostnames: + - "account.openeventhub.com" + - "openeventhub.com" + - "api.openeventhub.com" \ No newline at end of file diff --git a/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs b/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs index 44632cc..deac090 100644 --- a/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs +++ b/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs @@ -14,6 +14,8 @@ using EventHub.Web; using EventHub.Web.Theme; using EventHub.Web.Theme.Bundling; using IdentityServer4.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; using StackExchange.Redis; using Volo.Abp; @@ -28,6 +30,7 @@ using Volo.Abp.Autofac; using Volo.Abp.BackgroundJobs; using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; +using Volo.Abp.IdentityServer; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation.Urls; @@ -50,10 +53,36 @@ namespace EventHub public override void PreConfigureServices(ServiceConfigurationContext context) { - PreConfigure(builder => + var hostingEnvironment = context.Services.GetHostingEnvironment(); + + if (!hostingEnvironment.IsDevelopment()) { - builder.AddSigningCredential(new X509Certificate2("localhost.pfx", "e8202f07-66e5-4619-be07-72ba76fde97f")); - }); + var configuration = context.Services.GetConfiguration(); + + PreConfigure(options => + { + options.AddDeveloperSigningCredential = false; + }); + + PreConfigure(builder => + { + builder.AddSigningCredential(GetSigningCertificate(hostingEnvironment, configuration)); + }); + } + } + + private X509Certificate2 GetSigningCertificate(IWebHostEnvironment hostingEnv, IConfiguration configuration) + { + var fileName = "localhost.pfx"; + var passPhrase = "e8202f07-66e5-4619-be07-72ba76fde97f"; + var file = Path.Combine(hostingEnv.ContentRootPath, fileName); + + if (!File.Exists(file)) + { + throw new FileNotFoundException($"Signing Certificate couldn't found: {file}"); + } + + return new X509Certificate2(file, passPhrase); } public override void ConfigureServices(ServiceConfigurationContext context)