diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs index a5dff1ac..765579ff 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs @@ -19,6 +19,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; using StackExchange.Redis; using System; using System.Net.Http.Headers; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.HttpOverrides; using Polly; using Volo.Abp; @@ -150,6 +151,37 @@ public class EShopOnAbpPublicWebModule : AbpModule options.Scope.Add("PaymentService"); options.Scope.Add("OrderingService"); }); + if (Convert.ToBoolean(configuration["AuthServer:IsOnProd"])) + { + context.Services.Configure("oidc", options => + { + options.MetadataAddress = configuration["AuthServer:MetaAddress"].EnsureEndsWith('/') + + ".well-known/openid-configuration"; + + var previousOnRedirectToIdentityProvider = options.Events.OnRedirectToIdentityProvider; + options.Events.OnRedirectToIdentityProvider = async ctx => + { + // Intercept the redirection so the browser navigates to the right URL in your host + ctx.ProtocolMessage.IssuerAddress = configuration["AuthServer:Authority"].EnsureEndsWith('/') + "connect/authorize"; + + if (previousOnRedirectToIdentityProvider != null) + { + await previousOnRedirectToIdentityProvider(ctx); + } + }; + var previousOnRedirectToIdentityProviderForSignOut = options.Events.OnRedirectToIdentityProviderForSignOut; + options.Events.OnRedirectToIdentityProviderForSignOut = async ctx => + { + // Intercept the redirection for signout so the browser navigates to the right URL in your host + ctx.ProtocolMessage.IssuerAddress = configuration["AuthServer:Authority"].EnsureEndsWith('/') + "connect/endsession"; + + if (previousOnRedirectToIdentityProviderForSignOut != null) + { + await previousOnRedirectToIdentityProviderForSignOut(ctx); + } + }; + }); + } var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); context.Services diff --git a/etc/k8s/eshoponabp/charts/public-web/templates/public-web-deployment.yaml b/etc/k8s/eshoponabp/charts/public-web/templates/public-web-deployment.yaml index a6202ab9..1d644d77 100644 --- a/etc/k8s/eshoponabp/charts/public-web/templates/public-web-deployment.yaml +++ b/etc/k8s/eshoponabp/charts/public-web/templates/public-web-deployment.yaml @@ -29,6 +29,10 @@ spec: value: "{{ .Values.config.authServer.authority }}" - name: "AuthServer__RequireHttpsMetadata" value: "{{ .Values.config.authServer.requireHttpsMetadata }}" + - name: "AuthServer__IsOnProd" + value: "{{ .Values.config.authServer.isOnProd }}" + - name: "AuthServer__MetaAddress" + value: "{{ .Values.config.authServer.metaAddress }}" - name: "DOTNET_ENVIRONMENT" value: "{{ .Values.config.dotnetEnv }}" - name: "Redis__Configuration" diff --git a/etc/k8s/eshoponabp/charts/public-web/values.yaml b/etc/k8s/eshoponabp/charts/public-web/values.yaml index 12e3ab42..70b57265 100644 --- a/etc/k8s/eshoponabp/charts/public-web/values.yaml +++ b/etc/k8s/eshoponabp/charts/public-web/values.yaml @@ -4,6 +4,8 @@ config: authServer: authority: http://eshop-st-authserver requireHttpsMetadata: "false" + isOnProd: # + metaAddress: # dotnetEnv: Staging redisHost: eshop-st-redis rabbitmqHost: eshop-st-rabbitmq diff --git a/etc/k8s/eshoponabp/values.azure.yaml b/etc/k8s/eshoponabp/values.azure.yaml index 6f168878..b24c2f17 100644 --- a/etc/k8s/eshoponabp/values.azure.yaml +++ b/etc/k8s/eshoponabp/values.azure.yaml @@ -44,8 +44,10 @@ public-web: selfUrl: https://eshoponabp.com gatewayUrl: https://gateway-public.eshoponabp.com/ authServer: - authority: https://auth.eshoponabp.com + authority: http://eshop-az-authserver requireHttpsMetadata: "false" + isOnProd: "true" + metaAddress: https://auth.eshoponabp.com dotnetEnv: Production redisHost: eshop-az-redis rabbitmqHost: eshop-az-rabbitmq @@ -101,7 +103,7 @@ administration: administrationService: "Host=eshop-az-postgresdb;Port=5432;Database=EShopOnAbp_Administration;User ID=postgres;password=myPassw0rd;Pooling=false" authServer: authority: http://eshop-az-authserver - requireHttpsMetadata: "false" + requireHttpsMetadata: "false" swaggerClientId: WebGateway_Swagger swaggerClientSecret: "1q2w3e*" remoteServices: