Example #1
0
 public UserRepository(
     GraphServiceClient graphServiceClient,
     AzureAdB2CConfiguration configuration,
     ILogger <UserRepository> logger,
     TemporaryPasswordService temporaryPasswordService)
 {
     _graphServiceClient       = graphServiceClient;
     _configuration            = configuration;
     _logger                   = logger;
     _temporaryPasswordService = temporaryPasswordService;
     _userPrincipalNameInvalidCharacterReplacement = '-';
     _nonLetterOrNumberPattern = new Regex("[^a-zA-Z0-9æÆøØåÅ]");
     _specialCharacters        = "!#$%&'()*+,-./:;<=>?@[]^_`{|}~";
 }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Enables Application Insights telemetry.
            services.AddApplicationInsightsTelemetry();
            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
                loggingBuilder.AddConsole();
                loggingBuilder.AddDebug();
                loggingBuilder.AddAzureWebAppDiagnostics();
            });

            services.AddControllers(o =>
            {
                o.AllowEmptyInputInBodyModelBinding = true;
            }).AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
            this.ConfigureSwagger(services);

            var essAzureADConfiguration = new AzureADConfiguration();

            configuration.Bind("ESSAzureADConfiguration", essAzureADConfiguration);

            var azureAdB2CConfiguration = new AzureAdB2CConfiguration();

            configuration.Bind("AzureAdB2CConfiguration", azureAdB2CConfiguration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer("AzureAD", options =>
            {
                options.Audience  = essAzureADConfiguration.ClientId;
                options.Authority = $"{essAzureADConfiguration.MicrosoftOnlineLoginUrl}{essAzureADConfiguration.TenantId}";
            })
            .AddJwtBearer("AzureB2C", jwtOptions =>
            {
                jwtOptions.Audience  = azureAdB2CConfiguration.ClientId;
                jwtOptions.Authority = $"{azureAdB2CConfiguration.Instance}{azureAdB2CConfiguration.Domain}/{azureAdB2CConfiguration.SignUpSignInPolicy}/v2.0/";
            })
            .AddJwtBearer("AzureADB2C", options =>
            {
                options.Audience  = azureAdB2CConfiguration.ClientId;
                options.Authority = $"{essAzureADConfiguration.MicrosoftOnlineLoginUrl}{azureAdB2CConfiguration.TenantId}";
                options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidAudience = azureAdB2CConfiguration.ClientId,
                    ValidIssuer   = $"{essAzureADConfiguration.MicrosoftOnlineLoginUrl}{azureAdB2CConfiguration.TenantId}/v2.0"
                };
            });

            services.AddAuthorization(options =>
            {
                options.DefaultPolicy = new AuthorizationPolicyBuilder()
                                        .RequireAuthenticatedUser()
                                        .AddAuthenticationSchemes("AzureAD", "AzureB2C", "AzureADB2C")
                                        .Build();
            });

            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });
            services.Configure <EssFulfilmentStorageConfiguration>(configuration.GetSection("ESSFulfilmentConfiguration"));
            services.Configure <CacheConfiguration>(configuration.GetSection("CacheConfiguration"));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IAuthFssTokenProvider, AuthFssTokenProvider>();
            services.AddSingleton <IAuthScsTokenProvider, AuthScsTokenProvider>();
            services.AddScoped <ISalesCatalogueService, SalesCatalogueService>();
            services.AddScoped <ISalesCatalogueStorageService, SalesCatalogueStorageService>();
            services.AddScoped <IAzureBlobStorageService, AzureBlobStorageService>();
            services.AddScoped <IAzureBlobStorageClient, AzureBlobStorageClient>();
            services.AddScoped <IAzureMessageQueueHelper, AzureMessageQueueHelper>();
            services.AddScoped <IAzureTableStorageClient, AzureTableStorageClient>();
            services.AddScoped <IFileShareServiceCache, FileShareServiceCache>();
            services.AddScoped <IAzureAdB2CHelper, AzureAdB2CHelper>();
            services.AddAutoMapper(Assembly.GetExecutingAssembly());
            services.AddApplicationInsightsTelemetry();

            services.AddHeaderPropagation(options =>
            {
                options.Headers.Add(CorrelationIdMiddleware.XCorrelationIdHeaderKey);
            });

            services.Configure <SalesCatalogueConfiguration>(configuration.GetSection("SalesCatalogue"));

            var retryCount    = Convert.ToInt32(configuration["RetryConfiguration:RetryCount"]);
            var sleepDuration = Convert.ToDouble(configuration["RetryConfiguration:SleepDuration"]);

            services.AddHttpClient <ISalesCatalogueClient, SalesCatalogueClient>(client =>
            {
                client.BaseAddress     = new Uri(configuration["SalesCatalogue:BaseUrl"]);
                var productHeaderValue = new ProductInfoHeaderValue(ExchangeSetService,
                                                                    Assembly.GetExecutingAssembly().GetCustomAttributes <AssemblyFileVersionAttribute>().Single().Version);
                client.DefaultRequestHeaders.UserAgent.Add(productHeaderValue);
            }
                                                                                 )
            .AddHeaderPropagation().AddPolicyHandler((services, request) => CommonHelper.GetRetryPolicy(services.GetService <ILogger <ISalesCatalogueClient> >(), "Sales Catalogue", EventIds.RetryHttpClientSCSRequest, retryCount, sleepDuration));

            services.Configure <FileShareServiceConfiguration>(configuration.GetSection("FileShareService"));
            services.Configure <EssManagedIdentityConfiguration>(configuration.GetSection("ESSManagedIdentity"));
            services.Configure <AzureAdB2CConfiguration>(configuration.GetSection("AzureAdB2CConfiguration"));
            services.Configure <AzureADConfiguration>(configuration.GetSection("ESSAzureADConfiguration"));

            services.AddHttpClient <IFileShareServiceClient, FileShareServiceClient>(client =>
            {
                client.BaseAddress     = new Uri(configuration["FileShareService:BaseUrl"]);
                var productHeaderValue = new ProductInfoHeaderValue(ExchangeSetService,
                                                                    Assembly.GetExecutingAssembly().GetCustomAttributes <AssemblyFileVersionAttribute>().Single().Version);
                client.DefaultRequestHeaders.UserAgent.Add(productHeaderValue);
            }
                                                                                     )

            .AddHeaderPropagation().AddPolicyHandler((services, request) => CommonHelper.GetRetryPolicy(services.GetService <ILogger <IFileShareServiceClient> >(), "File Share", EventIds.RetryHttpClientFSSRequest, retryCount, sleepDuration));
            services.AddScoped <IFileSystemHelper, FileSystemHelper>();
            services.AddScoped <IFileShareService, FileShareService>();
            services.AddScoped <IProductDataService, ProductDataService>();
            services.AddScoped <IMonitorHelper, MonitorHelper>();
            services.AddScoped <IProductIdentifierValidator, ProductIdentifierValidator>();
            services.AddScoped <IProductDataProductVersionsValidator, ProductDataProductVersionsValidator>();
            services.AddScoped <IProductDataSinceDateTimeValidator, ProductDataSinceDateTimeValidator>();
            services.AddScoped <IExchangeSetStorageProvider, ExchangeSetStorageProvider>();
            services.AddScoped <IEventHubLoggingHealthClient, EventHubLoggingHealthClient>();
            services.AddSingleton <ISmallExchangeSetInstance, SmallExchangeSetInstance>();
            services.AddSingleton <IMediumExchangeSetInstance, MediumExchangeSetInstance>();
            services.AddSingleton <ILargeExchangeSetInstance, LargeExchangeSetInstance>();
            services.AddScoped <IAzureWebJobsHealthCheckClient, AzureWebJobsHealthCheckClient>();
            services.AddScoped <IAzureWebJobsHealthCheckService, AzureWebJobsHealthCheckService>();
            services.AddSingleton <IWebJobsAccessKeyProvider>(s => new WebJobsAccessKeyProvider(configuration));
            services.AddScoped <UserIdentifier>();

            services.AddHealthChecks()
            .AddCheck <FileShareServiceHealthCheck>("FileShareServiceHealthCheck")
            .AddCheck <SalesCatalogueServiceHealthCheck>("SalesCatalogueServiceHealthCheck")
            .AddCheck <EventHubLoggingHealthCheck>("EventHubLoggingHealthCheck")
            .AddCheck <AzureBlobStorageHealthCheck>("AzureBlobStorageHealthCheck")
            .AddCheck <AzureMessageQueueHealthCheck>("AzureMessageQueueHealthCheck")
            .AddCheck <AzureWebJobsHealthCheck>("AzureWebJobsHealthCheck");
            services.AddDistributedMemoryCache();

            services.AddScoped <IEnterpriseEventCacheDataRequestValidator, EnterpriseEventCacheDataRequestValidator>();
            services.AddScoped <IEssWebhookService, EssWebhookService>();
        }
Example #3
0
 public ClientCredentialsProvider(IConfidentialClientApplication confidentialClientApplication, AzureAdB2CConfiguration configuration)
 {
     _confidentialClientApplication = confidentialClientApplication;
     _configuration = configuration;
 }