public AzureB2CAuthClient(IOptions <OpenIDConnectSettings> settings, SecurityTokenHandler securityTokenHandler, IConfigurationManager <OpenIdConnectConfiguration> configurationManager)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.settings             = settings.Value;
            this.configurationManager = configurationManager;
            tokenHandler = securityTokenHandler;
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDataProtection();
            services.AddHttpContextAccessor();
            services.AddApplicationInsightsTelemetry();

            services.AddTransient <IApplicationService, ApplicationService>();
            services.AddTransient <IAsyncHelper, AsyncHelper>();
            services.AddTransient <IContentProcessorService, ContentProcessorService>();
            services.AddTransient <IHttpResponseMessageHandler, CookieHttpResponseMessageHandler>();
            services.AddTransient <ILoggerHelper, LoggerHelper>();
            services.AddTransient <IMapper <ApplicationModel, PageViewModel>, ApplicationToPageModelMapper>();
            services.AddTransient <ISetCookieParser, SetCookieParser>();
            services.AddTransient <IUrlRewriterService, UrlRewriterService>();
            services.AddTransient <ICompositeDataProtectionDataProvider, CompositeDataProtectionDataProvider>();

            services.AddTransient <CompositeSessionIdDelegatingHandler>();
            services.AddTransient <CookieDelegatingHandler>();
            services.AddTransient <UserAgentDelegatingHandler>();
            services.AddTransient <OriginalHostDelegatingHandler>();
            services.AddTransient <CompositeRequestDelegatingHandler>();
            services.AddTransient <IFakeHttpRequestSender, FakeHttpRequestSender>();
            services.AddTransient <SecurityTokenHandler, JwtSecurityTokenHandler>();
            services.AddTransient <INeo4JService, Neo4JService>();
            services.AddTransient <SecurityTokenHandler, JwtSecurityTokenHandler>();

            services.AddScoped <IPathLocator, UrlPathLocator>();
            services.AddScoped <IAppRegistryDataService, AppRegistryDataService>();
            services.AddScoped <IHeaderRenamerService, HeaderRenamerService>();
            services.AddScoped <IHeaderCountService, HeaderCountService>();
            services.AddScoped <IOpenIdConnectClient, AzureB2CAuthClient>();
            services.AddScoped <IVersionedFiles, VersionedFiles>();

            services.AddSingleton <IBearerTokenRetriever, BearerTokenRetriever>();
            services.AddSingleton <IShellRobotFileService, ShellRobotFileService>();
            services.AddSingleton <IBaseUrlService, BaseUrlService>();
            services.AddSingleton <IFileInfoHelper, FileInfoHelper>();
            services.AddSingleton <ITaskHelper, TaskHelper>();
            services.AddSingleton(Configuration.GetSection(nameof(MarkupMessages)).Get <MarkupMessages>() ?? new MarkupMessages());
            services.AddSingleton(Configuration.GetSection(nameof(WebchatOptions)).Get <WebchatOptions>() ?? new WebchatOptions());

            var authSettings = new OpenIDConnectSettings();

            Configuration.GetSection("OIDCSettings").Bind(authSettings);

            services.Configure <Neo4JSettings>(Configuration.GetSection(nameof(Neo4JSettings)));

            services.AddSingleton <IConfigurationManager <OpenIdConnectConfiguration> >(provider => new ConfigurationManager <OpenIdConnectConfiguration>(authSettings.OIDCConfigMetaDataUrl, new OpenIdConnectConfigurationRetriever(), new HttpDocumentRetriever()));

            services.Configure <OpenIDConnectSettings>(Configuration.GetSection("OIDCSettings"));
            services.Configure <AuthSettings>(Configuration.GetSection(nameof(AuthSettings)));

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
            {
                options.LoginPath = "/auth/signin";
            });

            var policyOptions  = Configuration.GetSection(Constants.Policies).Get <PolicyOptions>();
            var policyRegistry = services.AddPolicyRegistry();

            services.AddPolicies(policyRegistry, nameof(VisitClientOptions), policyOptions)
            .AddHttpClient <INeo4JService, Neo4JService, VisitClientOptions>(Configuration, nameof(VisitClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker));

            services
            .AddPolicies(policyRegistry, nameof(AppRegistryClientOptions), policyOptions)
            .AddHttpClient <IAppRegistryService, AppRegistryService, AppRegistryClientOptions>(Configuration, nameof(AppRegistryClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker));

            services
            .AddPolicies(policyRegistry, nameof(ApplicationClientOptions), policyOptions)
            .AddHttpClient <IContentRetriever, ContentRetriever, ApplicationClientOptions>(Configuration, nameof(ApplicationClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker))
            .AddHttpMessageHandler <CompositeSessionIdDelegatingHandler>()
            .AddHttpMessageHandler <CookieDelegatingHandler>();

            services
            .AddPolicies(policyRegistry, nameof(AjaxRequestClientOptions), policyOptions)
            .AddHttpClient <IAjaxRequestService, AjaxRequestService, AjaxRequestClientOptions>(Configuration, nameof(AjaxRequestClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker));

            services
            .AddPolicies(policyRegistry, nameof(AuthClientOptions), policyOptions);

            services
            .AddPolicies(policyRegistry, nameof(HealthClientOptions), policyOptions)
            .AddHttpClient <IApplicationHealthService, ApplicationHealthService, HealthClientOptions>(Configuration, nameof(HealthClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker));

            services
            .AddPolicies(policyRegistry, nameof(SitemapClientOptions), policyOptions)
            .AddHttpClient <IApplicationSitemapService, ApplicationSitemapService, SitemapClientOptions>(Configuration, nameof(SitemapClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker));

            services
            .AddPolicies(policyRegistry, nameof(RobotClientOptions), policyOptions)
            .AddHttpClient <IApplicationRobotService, ApplicationRobotService, RobotClientOptions>(Configuration, nameof(RobotClientOptions), nameof(PolicyOptions.HttpRetry), nameof(PolicyOptions.HttpCircuitBreaker));

            services.AddSession();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddRazorPages();
            services.AddControllersWithViews();
        }
 public AzureB2CAuthClient(IOptions <OpenIDConnectSettings> settings, IRestClient client)
 {
     _restClient = client;
     _settings   = settings.Value;
 }
 public AzureB2CAuthClient(IOptions <OpenIDConnectSettings> settings)
 {
     _restClient = new RestClient();
     _settings   = settings.Value;
 }