Browse Source

Added OpenIdConnect options for public-web application

pull/121/head
Galip Tolga Erdem 4 years ago
parent
commit
3d6cfc1f63
  1. 32
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs
  2. 4
      etc/k8s/eshoponabp/charts/public-web/templates/public-web-deployment.yaml
  3. 2
      etc/k8s/eshoponabp/charts/public-web/values.yaml
  4. 6
      etc/k8s/eshoponabp/values.azure.yaml

32
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<OpenIdConnectOptions>("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

4
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"

2
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

6
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:

Loading…
Cancel
Save