// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <AzureAdB2COptions>(Configuration.GetSection("Authentication:AzureAdB2C"));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout    = TimeSpan.FromHours(1);
                options.CookieHttpOnly = true;
            });

            var sp = services.BuildServiceProvider();
            AzureAdB2COptions AzureAdB2COptions = new AzureAdB2COptions();

            Configuration.GetSection("Authentication:AzureAdB2C").Bind(AzureAdB2COptions);
            services.AddAuthentication(auth =>
            {
                auth.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                auth.DefaultChallengeScheme    = OpenIdConnectDefaults.AuthenticationScheme;
                auth.DefaultSignInScheme       = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                OpenIdConnectOptionsSetup OpenIdConnectOptionsSetup = new OpenIdConnectOptionsSetup(AzureAdB2COptions);
                options.ClientId                  = OpenIdConnectOptionsSetup.AzureAdB2COptions.ClientId;
                options.Authority                 = OpenIdConnectOptionsSetup.AzureAdB2COptions.Authority;
                options.UseTokenLifetime          = true;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    NameClaimType = "name"
                };

                options.Events = new OpenIdConnectEvents()
                {
                    OnRedirectToIdentityProvider = OpenIdConnectOptionsSetup.OnRedirectToIdentityProvider,
                    OnRemoteFailure             = OpenIdConnectOptionsSetup.OnRemoteFailure,
                    OnAuthorizationCodeReceived = OpenIdConnectOptionsSetup.OnAuthorizationCodeReceived
                };
            });

            services.AddMvc();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <AzureAdB2COptions>(Configuration.GetSection("Authentication:AzureAdB2C"));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Add framework services.
            services.AddMvc();

            // Adds a default in-memory implementation of IDistributedCache.
            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout     = TimeSpan.FromHours(1);
                options.Cookie.HttpOnly = true;
            });

            // TODO: Use following to configure OpenIdConnectOptions
            //services.AddSingleton<IConfigureOptions<OpenIdConnectOptions>, OpenIdConnectOptionsSetup>();

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignInScheme       = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                // TODO: Hack, use DI
                ServiceProvider serviceProvider = services.BuildServiceProvider();
                var b2cOptions = serviceProvider.GetService <IOptions <AzureAdB2COptions> >();

                var service = new OpenIdConnectOptionsSetup(b2cOptions);
                service.Configure(options);
            });
        }