1. Configured CookiePolicyOptions in the DI container

2. Used CookiePolicy MiddlwWare
This commit is contained in:
rafsanulhasan 2018-09-01 15:02:50 +06:00
parent 8110a95111
commit 6b96741de6

View File

@ -36,6 +36,11 @@ namespace Microsoft.eShopOnContainers.WebMVC
// This method gets called by the runtime. Use this method to add services to the IoC container. // This method gets called by the runtime. Use this method to add services to the IoC container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.Configure<CookiePolicyOptions>(opts =>
{
opts.CheckConsentNeeded = context => true;
opts.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAppInsight(Configuration) services.AddAppInsight(Configuration)
.AddHealthChecks(Configuration) .AddHealthChecks(Configuration)
.AddCustomMvc(Configuration) .AddCustomMvc(Configuration)
@ -69,6 +74,8 @@ namespace Microsoft.eShopOnContainers.WebMVC
} }
app.UseCookiePolicy();
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200));
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
@ -83,7 +90,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
app.UseAuthentication(); app.UseAuthentication();
var log = loggerFactory.CreateLogger("identity"); ILogger log = loggerFactory.CreateLogger("identity");
WebContextSeed.Seed(app, env, loggerFactory); WebContextSeed.Seed(app, env, loggerFactory);
@ -106,7 +113,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddApplicationInsightsTelemetry(configuration); services.AddApplicationInsightsTelemetry(configuration);
var orchestratorType = configuration.GetValue<string>("OrchestratorType"); string orchestratorType = configuration.GetValue<string>("OrchestratorType");
if (orchestratorType?.ToUpper() == "K8S") if (orchestratorType?.ToUpper() == "K8S")
{ {
@ -128,8 +135,8 @@ namespace Microsoft.eShopOnContainers.WebMVC
{ {
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
var minutes = 1; int minutes = 1;
if (int.TryParse(configuration["HealthCheck:Timeout"], out var minutesParsed)) if (int.TryParse(configuration["HealthCheck:Timeout"], out int minutesParsed))
{ {
minutes = minutesParsed; minutes = minutesParsed;
} }
@ -227,9 +234,9 @@ namespace Microsoft.eShopOnContainers.WebMVC
public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration)
{ {
var useLoadTest = configuration.GetValue<bool>("UseLoadTest"); bool useLoadTest = configuration.GetValue<bool>("UseLoadTest");
var identityUrl = configuration.GetValue<string>("IdentityUrl"); string identityUrl = configuration.GetValue<string>("IdentityUrl");
var callBackUrl = configuration.GetValue<string>("CallBackUrl"); string callBackUrl = configuration.GetValue<string>("CallBackUrl");
// Add Authentication services // Add Authentication services