public EmailController(ILoggerFactory loggerFactory, SqlServerDataSource sqlServerDataSource, IOptions <WebApiConfiguration> options, ICurrentUserRetriever currentUserRetriever, Jibberwock.Persistence.DataAccess.Utility.Interfaces.IHashCalculator hashCalculator) : base(loggerFactory, sqlServerDataSource, options, currentUserRetriever) { _hashCalculator = hashCalculator; _appInsightsConfiguration = options?.Value.AppInsightsConfiguration; }
public void Configure(IMvxPluginConfiguration configuration) { if (configuration == null) { throw new MvxException("The XamarinInsights need a PluginConfiguration, you didn't provide any"); } var config = configuration as AppInsightsConfiguration; if (config == null) { throw new MvxException("The XamarinInsights needs AppInsightsConfiguration, you provided: {0}", configuration.GetType()); } Config = config; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IConfiguration>(Configuration); services.AddOptions(); services.Configure <IdentityProviderConfiguration>(options => { Configuration.GetSection("azuread").Bind(options); IdentityProviderConfiguration.Validate(options); }); services.Configure <SearchConfiguration>(options => { Configuration.GetSection("search").Bind(options); SearchConfiguration.Validate(options); }); services.Configure <CosmosConfiguration>(options => { Configuration.GetSection("documents").Bind(options); CosmosConfiguration.Validate(options); }); services.Configure <StorageConfiguration>((config) => { Configuration.GetSection("storage").Bind(config); StorageConfiguration.Validate(config); }); services.Configure <BatchConfiguration>((config) => { Configuration.GetSection("batch").Bind(config); BatchConfiguration.Validate(config); }); services.Configure <AppInsightsConfiguration>((config) => { Configuration.GetSection("applicationinsights").Bind(config); AppInsightsConfiguration.Validate(config); }); var armTemplatesMap = new ArmTemplatesMap(); services.AddSingleton(armTemplatesMap); var staticAssetsMap = new StaticAssetsMap(); services.AddSingleton(staticAssetsMap); services.AddMemoryCache(); //services // .AddAuthentication(options => // { // options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; // options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; // }) // .AddJwtBearer(options => // { // options.Audience = Configuration["azureADConfig:clientId"]; // options.Authority = Configuration["azureADConfig:authority"]; // options.Events = new JwtBearerEvents // { // OnMessageReceived = FetchAuthTokenFromCookie, // OnTokenValidated = async context => // { // var principal = context.Principal; // var ODREmailList = Configuration["ODRAdminList"].Split(";"); // } // }; // }); //services // .AddAuthentication(options => // { // options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; // }) // .AddJwtBearer(options => // { // options.Audience = Configuration["azureADConfig:clientId"]; // options.Authority = Configuration["azureADConfig:authority"]; // options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters // { // ValidAudience = Configuration["azureADConfig:clientId"], // ValidIssuer = $"https://login.microsoftonline.com/" + Configuration["azureADConfig:tenantId"] + "/v2.0" // }; // options.Events = new JwtBearerEvents // { // OnMessageReceived = FetchAuthTokenFromCookie, // //OnTokenValidated = async context => // //{ // // var principal = context.Principal; // // if (Configuration.GetChildren().Any(item => item.Key == "ODRAdminList") && principal.Claims.Any(c => c.Type == "preferred_username")) // // { // // var ODRAdminsList = Configuration["ODRAdminList"].Split(";").ToList(); // // var testSubject = principal.Claims.FirstOrDefault(c => c.Type == "preferred_username").Value; // // if (ODRAdminsList.Contains(testSubject)) // // { // // var claims = new List<Claim> // // { // // new Claim(ClaimTypes.Role, "ODRAdmin") // // }; // // var appIdentity = new ClaimsIdentity(claims); // // principal.AddIdentity(appIdentity); // // } // // } // //} // }; // }); services .AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { var tenantName = Configuration["AzureAD:Tenant"].Split('.').First(); var policyName = Configuration["AzureAD:Policy"]; var audience = Configuration["AzureAD:Audience"]; options.MetadataAddress = $"https://{tenantName}.b2clogin.com/{tenantName}.onmicrosoft.com/{policyName}/v2.0/.well-known/openid-configuration"; options.Audience = audience; options.Events = new JwtBearerEvents { OnMessageReceived = FetchAuthTokenFromCookie, OnAuthenticationFailed = context => { var ctx = context; return(Task.FromResult(0)); }, }; }); services.AddMvc(); services .AddAuthorization(options => { options.AddPolicy(PolicyNames.MustBeInAdminGroup, policy => { var authorizedAdminUsers = Configuration["AuthorizedAdminUsers"]; policy.Requirements.Add(new AzureActiveDirectoryGroupRequirement(authorizedAdminUsers)); }); }); services.AddSingleton <IAuthorizationHandler, AzureActiveDirectoryGroupHandler>(); //if (CurrentEnvironment.IsDevelopment()) //{ // services.AddSingleton<IAuthorizationHandler, DevelopmentOnlyNoAuthDirectoryGroupHandler>(); //} //else //{ // services.AddSingleton<IAuthorizationHandler, AzureActiveDirectoryGroupHandler>(); //} services.AddScoped <DatasetSearchService>(); services.AddScoped <UserDataSearchService>(); services.AddScoped <DatasetStorageService>(); services.AddScoped <AppInsightsService>(); services.AddScoped <UserDataStorageService>(); services.AddScoped <LicenseStorageService>(); services.AddScoped <SasTokenService>(); services.AddScoped <ValidationService>(); services.AddScoped <ApplicationJobs>(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ui-app"; }); // Add Swagger generator if (Configuration.GetValue <bool>("Application:EnableSwagger")) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "MSR ODR Admin API", Version = "v1" }); }); } }
public AppInsightsService(IOptions <AppInsightsConfiguration> options) { this.Configuration = options.Value; this.AppInsightsClient = new HttpClient(); }
public StatusController(ILoggerFactory loggerFactory, SqlServerDataSource sqlServerDataSource, IOptions <WebApiConfiguration> options, ICurrentUserRetriever currentUserRetriever) : base(loggerFactory, sqlServerDataSource, options, currentUserRetriever) { _appInsightsConfiguration = options?.Value.AppInsightsConfiguration; }