|
|
|
@ -40,190 +40,172 @@ using EShopOnAbp.PublicWeb.PaymentMethods; |
|
|
|
using EShopOnAbp.PaymentService.PaymentMethods; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
|
|
|
|
namespace EShopOnAbp.PublicWeb |
|
|
|
namespace EShopOnAbp.PublicWeb; |
|
|
|
|
|
|
|
[DependsOn( |
|
|
|
typeof(AbpCachingStackExchangeRedisModule), |
|
|
|
typeof(AbpEventBusRabbitMqModule), |
|
|
|
typeof(AbpAspNetCoreMvcClientModule), |
|
|
|
typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule), |
|
|
|
typeof(AbpHttpClientIdentityModelWebModule), |
|
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule), |
|
|
|
typeof(AbpAccountHttpApiClientModule), |
|
|
|
typeof(EShopOnAbpSharedHostingAspNetCoreModule), |
|
|
|
typeof(EShopOnAbpSharedLocalizationModule), |
|
|
|
typeof(CatalogServiceHttpApiClientModule), |
|
|
|
typeof(BasketServiceHttpApiClientModule), |
|
|
|
typeof(OrderingServiceHttpApiClientModule), |
|
|
|
typeof(AbpAspNetCoreSignalRModule), |
|
|
|
typeof(PaymentServiceHttpApiClientModule), |
|
|
|
typeof(AbpAutoMapperModule) |
|
|
|
)] |
|
|
|
public class EShopOnAbpPublicWebModule : AbpModule |
|
|
|
{ |
|
|
|
[DependsOn( |
|
|
|
typeof(AbpCachingStackExchangeRedisModule), |
|
|
|
typeof(AbpEventBusRabbitMqModule), |
|
|
|
typeof(AbpAspNetCoreMvcClientModule), |
|
|
|
typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule), |
|
|
|
typeof(AbpHttpClientIdentityModelWebModule), |
|
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule), |
|
|
|
typeof(AbpAccountHttpApiClientModule), |
|
|
|
typeof(EShopOnAbpSharedHostingAspNetCoreModule), |
|
|
|
typeof(EShopOnAbpSharedLocalizationModule), |
|
|
|
typeof(CatalogServiceHttpApiClientModule), |
|
|
|
typeof(BasketServiceHttpApiClientModule), |
|
|
|
typeof(OrderingServiceHttpApiClientModule), |
|
|
|
typeof(AbpAspNetCoreSignalRModule), |
|
|
|
typeof(PaymentServiceHttpApiClientModule), |
|
|
|
typeof(AbpAutoMapperModule) |
|
|
|
)] |
|
|
|
public class EShopOnAbpPublicWebModule : AbpModule |
|
|
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
|
|
|
context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => |
|
|
|
{ |
|
|
|
context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => |
|
|
|
{ |
|
|
|
options.AddAssemblyResource( |
|
|
|
typeof(EShopOnAbpResource), |
|
|
|
typeof(EShopOnAbpPublicWebModule).Assembly |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
options.AddAssemblyResource( |
|
|
|
typeof(EShopOnAbpResource), |
|
|
|
typeof(EShopOnAbpPublicWebModule).Assembly |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
context.Services.AddAutoMapperObjectMapper<EShopOnAbpPublicWebModule>(); |
|
|
|
Configure<AbpAutoMapperOptions>(options => { options.AddMaps<EShopOnAbpPublicWebModule>(validate: true); }); |
|
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
Configure<AbpBundlingOptions>(options => |
|
|
|
{ |
|
|
|
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
options.StyleBundles.Configure( |
|
|
|
BasicThemeBundles.Styles.Global, |
|
|
|
bundle => { bundle.AddContributors(typeof(CartWidgetStyleContributor)); } |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.AddAutoMapperObjectMapper<EShopOnAbpPublicWebModule>(); |
|
|
|
Configure<AbpAutoMapperOptions>(options => |
|
|
|
{ |
|
|
|
options.AddMaps<EShopOnAbpPublicWebModule>(validate: true); |
|
|
|
}); |
|
|
|
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = true; }); |
|
|
|
|
|
|
|
Configure<AbpBundlingOptions>(options => |
|
|
|
{ |
|
|
|
options.StyleBundles.Configure( |
|
|
|
BasicThemeBundles.Styles.Global, |
|
|
|
bundle => |
|
|
|
{ |
|
|
|
bundle.AddContributors(typeof(CartWidgetStyleContributor)); |
|
|
|
} |
|
|
|
); |
|
|
|
}); |
|
|
|
Configure<AbpDistributedCacheOptions>(options => { options.KeyPrefix = "EShopOnAbp:"; }); |
|
|
|
|
|
|
|
Configure<AbpMultiTenancyOptions>(options => |
|
|
|
{ |
|
|
|
options.IsEnabled = true; |
|
|
|
}); |
|
|
|
Configure<AppUrlOptions>(options => { options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; }); |
|
|
|
|
|
|
|
Configure<AbpDistributedCacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "EShopOnAbp:"; |
|
|
|
}); |
|
|
|
ConfigurePayment(configuration); |
|
|
|
|
|
|
|
Configure<AppUrlOptions>(options => |
|
|
|
context.Services.AddAuthentication(options => |
|
|
|
{ |
|
|
|
options.DefaultScheme = "Cookies"; |
|
|
|
options.DefaultChallengeScheme = "oidc"; |
|
|
|
}) |
|
|
|
.AddCookie("Cookies", options => { options.ExpireTimeSpan = TimeSpan.FromDays(365); }) |
|
|
|
.AddAbpOpenIdConnect("oidc", options => |
|
|
|
{ |
|
|
|
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; |
|
|
|
options.Authority = configuration["AuthServer:Authority"]; |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.ResponseType = OpenIdConnectResponseType.CodeIdToken; |
|
|
|
|
|
|
|
options.ClientId = configuration["AuthServer:ClientId"]; |
|
|
|
options.ClientSecret = configuration["AuthServer:ClientSecret"]; |
|
|
|
|
|
|
|
options.SaveTokens = true; |
|
|
|
options.GetClaimsFromUserInfoEndpoint = true; |
|
|
|
|
|
|
|
options.Scope.Add("role"); |
|
|
|
options.Scope.Add("email"); |
|
|
|
options.Scope.Add("phone"); |
|
|
|
options.Scope.Add("AccountService"); |
|
|
|
options.Scope.Add("AdministrationService"); |
|
|
|
options.Scope.Add("BasketService"); |
|
|
|
options.Scope.Add("CatalogService"); |
|
|
|
options.Scope.Add("PaymentService"); |
|
|
|
options.Scope.Add("OrderingService"); |
|
|
|
}); |
|
|
|
|
|
|
|
ConfigurePayment(configuration); |
|
|
|
|
|
|
|
context.Services.AddAuthentication(options => |
|
|
|
{ |
|
|
|
options.DefaultScheme = "Cookies"; |
|
|
|
options.DefaultChallengeScheme = "oidc"; |
|
|
|
}) |
|
|
|
.AddCookie("Cookies", options => |
|
|
|
{ |
|
|
|
options.ExpireTimeSpan = TimeSpan.FromDays(365); |
|
|
|
}) |
|
|
|
.AddAbpOpenIdConnect("oidc", options => |
|
|
|
{ |
|
|
|
options.Authority = configuration["AuthServer:Authority"]; |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.ResponseType = OpenIdConnectResponseType.CodeIdToken; |
|
|
|
|
|
|
|
options.ClientId = configuration["AuthServer:ClientId"]; |
|
|
|
options.ClientSecret = configuration["AuthServer:ClientSecret"]; |
|
|
|
|
|
|
|
options.SaveTokens = true; |
|
|
|
options.GetClaimsFromUserInfoEndpoint = true; |
|
|
|
|
|
|
|
options.Scope.Add("role"); |
|
|
|
options.Scope.Add("email"); |
|
|
|
options.Scope.Add("phone"); |
|
|
|
options.Scope.Add("AccountService"); |
|
|
|
options.Scope.Add("AdministrationService"); |
|
|
|
options.Scope.Add("BasketService"); |
|
|
|
options.Scope.Add("CatalogService"); |
|
|
|
options.Scope.Add("PaymentService"); |
|
|
|
options.Scope.Add("OrderingService"); |
|
|
|
}); |
|
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|
|
|
context.Services |
|
|
|
.AddDataProtection() |
|
|
|
.PersistKeysToStackExchangeRedis(redis, "EShopOnAbp-Protection-Keys") |
|
|
|
.SetApplicationName("eShopOnAbp-PublicWeb"); |
|
|
|
|
|
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|
|
|
context.Services |
|
|
|
.AddDataProtection() |
|
|
|
.PersistKeysToStackExchangeRedis(redis, "EShopOnAbp-Protection-Keys") |
|
|
|
.SetApplicationName("eShopOnAbp-PublicWeb"); |
|
|
|
Configure<AbpNavigationOptions>(options => |
|
|
|
{ |
|
|
|
options.MenuContributors.Add(new EShopOnAbpPublicWebMenuContributor(configuration)); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpNavigationOptions>(options => |
|
|
|
{ |
|
|
|
options.MenuContributors.Add(new EShopOnAbpPublicWebMenuContributor(configuration)); |
|
|
|
}); |
|
|
|
Configure<AbpToolbarOptions>(options => |
|
|
|
{ |
|
|
|
options.Contributors.Add(new EShopOnAbpPublicWebToolbarContributor()); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpToolbarOptions>(options => |
|
|
|
context.Services |
|
|
|
.AddReverseProxy() |
|
|
|
.LoadFromConfig(configuration.GetSection("ReverseProxy")) |
|
|
|
.AddTransforms(builderContext => |
|
|
|
{ |
|
|
|
options.Contributors.Add(new EShopOnAbpPublicWebToolbarContributor()); |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services |
|
|
|
.AddReverseProxy() |
|
|
|
.LoadFromConfig(configuration.GetSection("ReverseProxy")) |
|
|
|
.AddTransforms(builderContext => |
|
|
|
builderContext.AddRequestTransform(async (transformContext) => |
|
|
|
{ |
|
|
|
builderContext.AddRequestTransform(async (transformContext) => |
|
|
|
{ |
|
|
|
transformContext.ProxyRequest.Headers |
|
|
|
.Authorization = new AuthenticationHeaderValue( |
|
|
|
"Bearer", |
|
|
|
await transformContext.HttpContext.GetTokenAsync("access_token") |
|
|
|
); |
|
|
|
}); |
|
|
|
transformContext.ProxyRequest.Headers |
|
|
|
.Authorization = new AuthenticationHeaderValue( |
|
|
|
"Bearer", |
|
|
|
await transformContext.HttpContext.GetTokenAsync("access_token") |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigurePayment(IConfiguration configuration) |
|
|
|
private void ConfigurePayment(IConfiguration configuration) |
|
|
|
{ |
|
|
|
Configure<EShopOnAbpPublicWebPaymentOptions>(options => |
|
|
|
{ |
|
|
|
Configure<EShopOnAbpPublicWebPaymentOptions>(options => |
|
|
|
{ |
|
|
|
options.PaymentSuccessfulCallbackUrl = configuration["App:SelfUrl"].EnsureEndsWith('/') + "PaymentCompleted"; |
|
|
|
}); |
|
|
|
options.PaymentSuccessfulCallbackUrl = |
|
|
|
configuration["App:SelfUrl"].EnsureEndsWith('/') + "PaymentCompleted"; |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<PaymentMethodUiOptions>(options => |
|
|
|
{ |
|
|
|
options.ConfigureIcon(PaymentMethodNames.PayPal, "fa-cc-paypal paypal"); |
|
|
|
}); |
|
|
|
} |
|
|
|
Configure<PaymentMethodUiOptions>(options => |
|
|
|
{ |
|
|
|
options.ConfigureIcon(PaymentMethodNames.PayPal, "fa-cc-paypal paypal"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
var app = context.GetApplicationBuilder(); |
|
|
|
var env = context.GetEnvironment(); |
|
|
|
|
|
|
|
app.Use((ctx, next) => |
|
|
|
{ |
|
|
|
var app = context.GetApplicationBuilder(); |
|
|
|
var env = context.GetEnvironment(); |
|
|
|
|
|
|
|
app.Use((ctx, next) => |
|
|
|
{ |
|
|
|
ctx.Request.Scheme = "https"; |
|
|
|
return next(); |
|
|
|
}); |
|
|
|
ctx.Request.Scheme = "https"; |
|
|
|
return next(); |
|
|
|
}); |
|
|
|
|
|
|
|
if (env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
} |
|
|
|
if (env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
} |
|
|
|
|
|
|
|
app.UseAbpRequestLocalization(); |
|
|
|
app.UseAbpRequestLocalization(); |
|
|
|
|
|
|
|
if (!env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseErrorPage(); |
|
|
|
} |
|
|
|
|
|
|
|
app.UseCorrelationId(); |
|
|
|
app.UseStaticFiles(); |
|
|
|
app.UseRouting(); |
|
|
|
// app.UseHttpMetrics();
|
|
|
|
app.UseAuthentication(); |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
app.UseAuthorization(); |
|
|
|
app.UseConfiguredEndpoints(endpoints => |
|
|
|
{ |
|
|
|
endpoints.MapReverseProxy(); |
|
|
|
// endpoints.MapMetrics();
|
|
|
|
}); |
|
|
|
if (!env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseErrorPage(); |
|
|
|
} |
|
|
|
|
|
|
|
app.UseCorrelationId(); |
|
|
|
app.UseStaticFiles(); |
|
|
|
app.UseRouting(); |
|
|
|
// app.UseHttpMetrics();
|
|
|
|
app.UseAuthentication(); |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
app.UseAuthorization(); |
|
|
|
app.UseConfiguredEndpoints(endpoints => |
|
|
|
{ |
|
|
|
endpoints.MapReverseProxy(); |
|
|
|
// endpoints.MapMetrics();
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |