public void ReadsFixedIntervalRetryStrategyValuesFromConfiguration() { IConfigurationSection?section = this.retryManagerOptions?.RetryStrategy?.GetSection("Fixed Interval Non Default"); FixedIntervalOptions data = section.Get <FixedIntervalOptions>(); Assert.AreEqual("Fixed Interval Non Default", section?.Key); Assert.AreEqual(new TimeSpan(0, 0, 2), data.RetryInterval); Assert.AreEqual(2, data.RetryCount); Assert.AreEqual(false, data.FastFirstRetry); }
private bool?GetValueBool(string key, IConfigurationSection?productConfigSection, IConfigurationSection newRelicConfigSection) { string valStr = productConfigSection?[key] ?? newRelicConfigSection[key]; if (!string.IsNullOrEmpty(valStr) && bool.TryParse(valStr, out var valBool)) { return(valBool); } return(null); }
private int?GetValueInt(string key, IConfigurationSection?productConfigSection, IConfigurationSection newRelicConfigSection) { string valStr = productConfigSection?[key] ?? newRelicConfigSection[key]; if (!string.IsNullOrEmpty(valStr) && int.TryParse(valStr, out var valInt)) { return(valInt); } return(null); }
/// <summary> /// Constructor. /// </summary> /// <param name="services">The services being configured.</param> /// <param name="configurationSection">Optional configuration section.</param> protected MicrosoftIdentityBaseAuthenticationBuilder( IServiceCollection services, IConfigurationSection?configurationSection = null) { Services = services; ConfigurationSection = configurationSection; LoggingOptions logOptions = new LoggingOptions(); configurationSection?.Bind(logOptions); IdentityModelEventSource.ShowPII = logOptions.EnablePiiLogging; }
public void ReadsExponentialBackoffRetryStrategyValuesFromConfiguration() { IConfigurationSection? section = this.retryManagerOptions?.RetryStrategy?.GetSection("Exponential Backoff Non Default"); ExponentialBackoffOptions data = section.Get <ExponentialBackoffOptions>(); Assert.AreEqual("Exponential Backoff Non Default", section?.Key); Assert.AreEqual(new TimeSpan(0, 0, 1), data.MinBackOff); Assert.AreEqual(new TimeSpan(0, 0, 2), data.MaxBackOff); Assert.AreEqual(TimeSpan.FromMilliseconds(300), data.DeltaBackOff); Assert.AreEqual(4, data.RetryCount); Assert.AreEqual(false, data.FastFirstRetry); }
internal MicrosoftIdentityWebApiAuthenticationBuilderWithConfiguration( IServiceCollection services, string jwtBearerAuthenticationScheme, Action <JwtBearerOptions> configureJwtBearerOptions, Action <MicrosoftIdentityOptions> configureMicrosoftIdentityOptions, IConfigurationSection?configurationSection) : base(services, jwtBearerAuthenticationScheme, configureJwtBearerOptions, configureMicrosoftIdentityOptions, configurationSection) { if (configurationSection == null) { throw new ArgumentNullException(nameof(configurationSection)); } }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationDelegate"/> class. /// </summary> /// <param name="logger">The injected logger provider.</param> /// <param name="config">The configuration.</param> /// <param name="httpClientService">The injected http client service.</param> public AuthenticationDelegate( ILogger <IAuthenticationDelegate> logger, IConfiguration config, IHttpClientService httpClientService) { this.logger = logger; this.httpClientService = httpClientService; IConfigurationSection?configSection = config?.GetSection(ConfigSectionName); this.TokenUri = configSection.GetValue <Uri>(@"TokenUri"); this.TokenRequest = new ClientCredentialsTokenRequest(); configSection.Bind(this.TokenRequest); // Client ID, Client Secret, Audience, Username, Password }
private void ConfigureCountly() { // TODO: Move metrics related things to own class. IConfigurationSection?section = this.Configuration.GetSection("Countly"); CountlyConfig cc = new CountlyConfig { appKey = section["AppKey"], serverUrl = section["ServerUrl"], appVersion = BuildInfo.Current.InformationalVersion }; Countly.Instance.Init(cc); Countly.Instance.SessionBegin(); CountlyBase.IsLoggingEnabled = true; }
/// <summary> /// Constructor. /// </summary> /// <param name="services"> The services being configured.</param> /// <param name="openIdConnectScheme">Default scheme used for OpenIdConnect.</param> /// <param name="configureMicrosoftIdentityOptions">Action called to configure /// the <see cref="MicrosoftIdentityOptions"/>Microsoft identity options.</param> /// <param name="configurationSection">Optional configuration section.</param> internal MicrosoftIdentityWebAppAuthenticationBuilder( IServiceCollection services, string openIdConnectScheme, Action <MicrosoftIdentityOptions> configureMicrosoftIdentityOptions, IConfigurationSection?configurationSection) : base(services, configurationSection) { OpenIdConnectScheme = openIdConnectScheme; ConfigureMicrosoftIdentityOptions = configureMicrosoftIdentityOptions; if (ConfigureMicrosoftIdentityOptions == null) { throw new ArgumentNullException(nameof(configureMicrosoftIdentityOptions)); } }
public static IHostBuilder CreateHostBuilder(string[] args) { return(Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((context, builder) => { builder.AddJsonFile("hoff.json"); }) .ConfigureLogging((hostingContext, builder) => { IConfigurationSection?configuration = hostingContext.Configuration.GetSection("Logging"); builder.AddFile(configuration); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); })); }
// --- public AppConfig() { string?environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT"); // Set up configuration sources. IConfigurationBuilder?builder = new ConfigurationBuilder() .SetBasePath(Path.Combine(AppContext.BaseDirectory)) .AddJsonFile($"{APP_SETTING_FILE}.json", true, true) .AddJsonFile( Path.Combine(AppContext.BaseDirectory, string.Format("..{0}..{0}..{0}", Path.DirectorySeparatorChar), $"{APP_SETTING_FILE}.{environmentName}.json"), optional: true ); // Load json file this.Configuration = builder.Build(); // Console.WriteLine( this.Configuration[ "BasePath" ] ); IConfigurationSection?rawData = this.Configuration.GetSection("RawConfig"); IConfigurationSection?outputData = this.Configuration.GetSection("OutputConfig"); IEnumerable <KeyValuePair <string, string> >?citiesDirectory = rawData.GetSection("CitiesDirectory").AsEnumerable(); IEnumerable <KeyValuePair <string, string> >?companiesDirectory = rawData.GetSection("CompaniesDirectory").AsEnumerable(); IEnumerable <KeyValuePair <string, string> >?reportDirectory = rawData.GetSection("ReportDirectory").AsEnumerable(); // Setup the raw config data this.Raw = new RawConfig(this.Configuration["BasePath"], this.Configuration["RawConfig:CompanyCitiesPattern"], citiesDirectory, companiesDirectory, reportDirectory); // Setup the output config data this.Out = new OutputConfig(this.Configuration["BasePath"], outputData["Cities"], outputData["Companies"]); }
/// <summary> /// Initializes a new instance of the <see cref="NotificationSettingsJob"/> class. /// </summary> /// <param name="configuration">The configuration to use.</param> /// <param name="logger">The logger to use.</param> /// <param name="notificationSettingsDelegate">The email delegate to use.</param> /// <param name="authDelegate">The OAuth2 authentication service.</param> /// <param name="eventLogDelegate">The Eventlog delegate.</param> public NotificationSettingsJob( IConfiguration configuration, ILogger <NotificationSettingsJob> logger, INotificationSettingsDelegate notificationSettingsDelegate, IAuthenticationDelegate authDelegate, IEventLogDelegate eventLogDelegate) { this.configuration = configuration !; this.logger = logger; this.notificationSettingsDelegate = notificationSettingsDelegate; this.authDelegate = authDelegate; this.eventLogDelegate = eventLogDelegate; this.jobEnabled = this.configuration.GetSection(JobConfigKey).GetValue <bool>(JobEnabledKey, true); IConfigurationSection?configSection = configuration?.GetSection(AuthConfigSectionName); this.tokenUri = configSection.GetValue <Uri>(@"TokenUri"); this.tokenRequest = new ClientCredentialsTokenRequest(); configSection.Bind(this.tokenRequest); // Client ID, Client Secret, Audience, Username, Password }
public void ConfigureServices(IServiceCollection services) { services .AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new LocalDateJsonConverter("yyyyMMdd")); }); IConfigurationSection?hoffConfig = Configuration.GetSection("hoff"); services .Configure <CourseOptions>(hoffConfig) .Configure <CbrOptions>(hoffConfig); services .AddSingleton <IGeometryService, GeometryService>() .AddSingleton <ICbrService, CbrService>() .AddSingleton <IDataProvider, DataProvider>() .AddSingleton <ICourseService, CourseService>(); }
/// <summary> /// Allows a higher level abstraction of security token (i.e. System.IdentityModel.Tokens.Jwt and more modern, Microsoft.IdentityModel.JsonWebTokens) /// to be used with Microsoft Identity Web. /// Developers should continue to use `EnableTokenAcquisitionToCallDownstreamApi`. /// This API is not considered part of the public API and may change. /// </summary> /// <param name="configureConfidentialClientApplicationOptions">The action to configure <see cref="ConfidentialClientApplicationOptions"/>.</param> /// <param name="authenticationScheme">Authentication scheme.</param> /// <param name="services">The services being configured.</param> /// <param name="configuration">IConfigurationSection.</param> /// <returns>The authentication builder to chain.</returns> public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder EnableTokenAcquisition( Action <ConfidentialClientApplicationOptions> configureConfidentialClientApplicationOptions, string authenticationScheme, IServiceCollection services, IConfigurationSection?configuration) { services.AddOptions <ConfidentialClientApplicationOptions>(authenticationScheme) .Configure <IOptionsMonitor <MergedOptions> >(( ccaOptions, mergedOptionsMonitor) => { configureConfidentialClientApplicationOptions(ccaOptions); MergedOptions mergedOptions = mergedOptionsMonitor.Get(authenticationScheme); configuration?.Bind(mergedOptions); MergedOptions.UpdateMergedOptionsFromConfidentialClientApplicationOptions(ccaOptions, mergedOptions); }); services.AddTokenAcquisition(); return(new MicrosoftIdentityAppCallsWebApiAuthenticationBuilder( services, configuration)); }
public UmbracoFileConfiguration(IConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } IConfigurationSection?appSettings = configuration.GetSection("Serilog:WriteTo"); IConfigurationSection?umbracoFileAppSettings = appSettings.GetChildren().LastOrDefault(x => x.GetValue <string>("Name") == "UmbracoFile"); if (umbracoFileAppSettings is not null) { IConfigurationSection?args = umbracoFileAppSettings.GetSection("Args"); RestrictedToMinimumLevel = args.GetValue(nameof(RestrictedToMinimumLevel), RestrictedToMinimumLevel); FileSizeLimitBytes = args.GetValue(nameof(FileSizeLimitBytes), FileSizeLimitBytes); RollingInterval = args.GetValue(nameof(RollingInterval), RollingInterval); FlushToDiskInterval = args.GetValue(nameof(FlushToDiskInterval), FlushToDiskInterval); RollOnFileSizeLimit = args.GetValue(nameof(RollOnFileSizeLimit), RollOnFileSizeLimit); RetainedFileCountLimit = args.GetValue(nameof(RetainedFileCountLimit), RetainedFileCountLimit); } }
/// <summary> /// Constructor. /// </summary> /// <param name="services">The services being configured.</param> /// <param name="jwtBearerAuthenticationScheme">Default scheme used for OpenIdConnect.</param> /// <param name="configureJwtBearerOptions">ACtion called to configure the JwtBearer options.</param> /// <param name="configureMicrosoftIdentityOptions">Action called to configure /// the <see cref="MicrosoftIdentityOptions"/>Microsoft identity options.</param> /// <param name="configurationSection">Configuration section from which to /// get parameters.</param> internal MicrosoftIdentityWebApiAuthenticationBuilder( IServiceCollection services, string jwtBearerAuthenticationScheme, Action <JwtBearerOptions> configureJwtBearerOptions, Action <MicrosoftIdentityOptions> configureMicrosoftIdentityOptions, IConfigurationSection?configurationSection) : base(services, configurationSection) { JwtBearerAuthenticationScheme = jwtBearerAuthenticationScheme; ConfigureJwtBearerOptions = configureJwtBearerOptions; ConfigureMicrosoftIdentityOptions = configureMicrosoftIdentityOptions; if (ConfigureMicrosoftIdentityOptions == null) { throw new ArgumentNullException(nameof(configureMicrosoftIdentityOptions)); } if (ConfigureJwtBearerOptions == null) { throw new ArgumentNullException(nameof(configureMicrosoftIdentityOptions)); } Services.Configure(configureMicrosoftIdentityOptions); }
public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration configuration) { Environment = webHostEnvironment; Configuration = configuration; Options = configuration.GetSection(nameof(XperienceOptions)); }
public static IServiceCollection AddAppleReceiptVerifier(this IServiceCollection services, IConfigurationSection?configSection, Action <AppleReceiptVerifierOptions>?configure, string name = AppleReceiptVerifierOptions.DefaultVerifierName) { if (configSection == null && configure == null) { throw new InvalidOperationException($"At least {nameof(configSection)} or {nameof(configure)} must be provided."); } bool isDefaultName = name == AppleReceiptVerifierOptions.DefaultVerifierName; var optionsBuilder = services.AddOptions <AppleReceiptVerifierOptions>(isDefaultName ? Options.Options.DefaultName : AppleReceiptVerifierOptions.ServicesPrefix + name); if (configSection != null) { optionsBuilder.Bind(configSection); // first config } if (configure != null) { optionsBuilder.Configure(configure); // then explicit options } optionsBuilder.Validate(o => !string.IsNullOrWhiteSpace(o.AppSecret), $"{nameof(AppleReceiptVerifierOptions.AppSecret)} must have a non-empty value."); if (isDefaultName) { services.AddHttpClient <IAppleReceiptVerifier, AppleReceiptVerifier>(); } else { services.AddHttpClient(AppleReceiptVerifierOptions.ServicesPrefix + name); services.TryAddScoped <IAppleReceiptVerifierResolver, AppleReceiptVerifierResolver>(); // don't use Singleton here or else we'd exhaust HttpClients' pool } return(services); }
internal MicrosoftIdentityAppCallsWebApiAuthenticationBuilder( IServiceCollection services, IConfigurationSection?configurationSection = null) : base(services, configurationSection) { }
public static IServiceCollection AddStoryblok(this IServiceCollection services, IConfigurationSection?configurationSection, Action <StoryblokOptions>?configure = null) { var options = new StoryblokOptions(); configurationSection?.Bind(options); services.Configure <StoryblokOptions>(storyblokOptions => { if (storyblokOptions != null) { configurationSection?.Bind(storyblokOptions); } if (configure != null && storyblokOptions != null) { configure.Invoke(storyblokOptions); } }); return(AddStoryblok(services)); }
private string?GetValueString(string key, IConfigurationSection?productConfigSection, IConfigurationSection newRelicConfigSection) { return(productConfigSection?[key] ?? newRelicConfigSection[key]); }
private TimeSpan?GetValueTimeSpan(string key, IConfigurationSection?productConfigSection, IConfigurationSection newRelicConfigSection) { var seconds = GetValueInt(key, productConfigSection, newRelicConfigSection); return(seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null); }
private Uri?GetValueUri(string key, IConfigurationSection?productConfigSection, IConfigurationSection newRelicConfigSection) { Uri.TryCreate(GetValueString(key, productConfigSection, newRelicConfigSection), UriKind.Absolute, out var uri); return(uri); }