public SphyrnidaeIdentityHelper(IHttpClientSettings http, IEncryption encryption, ICache cache, IDefaultUserRepo repo) : base(http, encryption) { Cache = cache; Cache.Options.Seconds = CacheOptions.Year; Repo = repo; }
protected WebServiceBase(IHttpClientFactory factory, IHttpClientSettings settings, IIdentityHelper identity, ILogger logger) { Factory = factory; Settings = settings; Identity = identity; Logger = logger; }
public ApiInformation(ILoggerInformation info, IApplicationSettings appSettings, IRequestData requestData, IHttpClientSettings httpSettings) : base(info, appSettings) { RequestData = requestData; HttpSettings = httpSettings; Category = "API"; }
/// <summary> /// Initializes a new <see cref="SendHttpRequestHandler"/>. /// </summary> /// <param name="cookieContainer">The <see cref="CookieContainer"/> to use in the requests (initializes a new one when <c>null</c>.)</param> /// <param name="httpClientSettings">An <see cref="IHttpClientSettings"/>.</param> public SendHttpRequestHandler(CookieContainer cookieContainer, IHttpClientSettings httpClientSettings) { _CookieContainer = cookieContainer ?? new CookieContainer(); _HttpClientSettings = httpClientSettings ?? throw new ArgumentNullException(nameof(httpClientSettings)); httpClientSettings.SettingChanged += RefreshHttpClient; RefreshHttpClient(null); }
public static OpenApiSecurityScheme SecurityScheme(IHttpClientSettings http) => new OpenApiSecurityScheme { Description = "JWT Token", In = ParameterLocation.Header, Name = http.JwtHeader, Type = SecuritySchemeType.ApiKey };
/// <summary> /// Initializes a new <see cref="HttpClient"/>. /// </summary> /// <remarks> /// Adds the <see cref="CookieSaveHandler"/> to <see cref="Handlers"/> if <paramref name="cookieJar"/> is not <c>null</c>. /// </remarks> /// <param name="cookieJar">The <see cref="ICookieJar"/> to use for the requests.</param> /// <param name="httpClientSettings">The <see cref="IHttpClientSettings"/> (uses <see cref="HttpClientSettings"/> if <c>null</c>.)</param> public HttpClient(ICookieJar cookieJar = null, IHttpClientSettings httpClientSettings = null) : this(cookieJar?.CookieContainer, httpClientSettings ?? new HttpClientSettings()) { if (cookieJar != null) { Handlers.Insert(0, new CookieSaveHandler(cookieJar)); } }
/// <summary> /// Initializes a new <see cref="HttpClient"/>. /// </summary> /// <param name="cookieContainer">The <see cref="CookieContainer"/> to use for the requests.</param> /// <param name="httpClientSettings">The <see cref="IHttpClientSettings"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="httpClientSettings"/></exception> public HttpClient(CookieContainer cookieContainer, IHttpClientSettings httpClientSettings) { if (httpClientSettings == null) { throw new ArgumentNullException(nameof(httpClientSettings)); } Handlers = new List <IHttpClientHandler>(); Handlers.Add(new SendHttpRequestHandler(cookieContainer, httpClientSettings)); }
public static HttpClient Build(IHttpClientSettings settings) { #if NETSTANDARD || NETCOREAPP3_1 || NET5_0 var handler = new HttpClientHandler { CheckCertificateRevocationList = false, SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls, ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; #elif NET46 var handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; #else var handler = new WebRequestHandler { ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; #endif if (!string.IsNullOrEmpty(settings.ClientX509Certificate2ThumbprintOrSubjectName)) { handler.ClientCertificateOptions = ClientCertificateOption.Manual; var x509Certificate2 = CertificateLoader.LoadCertificate(settings.ClientX509Certificate2ThumbprintOrSubjectName); handler.ClientCertificates.Add(x509Certificate2); } handler.AllowAutoRedirect = settings.AllowAutoRedirect == true; // If UseCookies enabled, httpClient ignores Cookie header handler.UseCookies = false; if (settings.WebProxySettings != null) { handler.UseProxy = true; handler.Proxy = new WebProxy(settings.WebProxySettings.Address); if (settings.WebProxySettings.UserName != null && settings.WebProxySettings.Password != null) { handler.Proxy.Credentials = new NetworkCredential(settings.WebProxySettings.UserName, settings.WebProxySettings.Password); } } #if !NETSTANDARD1_3 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback = (message, cert, chain, errors) => true; #endif return(new HttpClient(handler)); }
public UserPreferenceWebService( IHttpClientFactory factory, IHttpClientSettings settings, IIdentityHelper identity, ILogger logger, IEnvironmentSettings env, IApplicationSettings app ) : base(factory, settings, identity, logger) { Env = env; App = app; }
public SphyrnidaeApiAuthenticationWebService( IHttpClientFactory factory, IHttpClientSettings settings, IIdentityHelper identity, ILogger logger, IEnvironmentSettings env, IApplicationSettings app ) : base(factory, settings, identity, logger) { Env = env; App = app; }
public VariableWebService( IHttpClientFactory factory, IHttpClientSettings settings, IIdentityHelper identity, IEnvironmentSettings env, IApplicationSettings app ) : base(factory, settings, identity, new NonLogger()) { Env = env; App = app; }
protected virtual IHttpClient GetClientInstance(HttpMessageHandler handler, IHttpClientSettings settings) { var client = new HttpClientWrapper(new HttpClient(handler)); if (Settings.Timeout.HasValue) { client.Timeout = Settings.Timeout.Value; } Settings.RequestHeaderConfiguration?.Invoke(client.DefaultRequestHeaders); Settings.ClientConfiguration?.Invoke(client); return(client); }
public LoggerInformation(IHttpClientSettings httpSettings, IIdentityHelper identity, IRequestData requestData) { HttpSettings = httpSettings; IdentityHelper = identity; RequestData = requestData; }
protected override IHttpClient GetClientInstance(HttpMessageHandler handler, IHttpClientSettings settings) { return(_client); }
public MockHttpClientBuilder(IHttpClientSettings settings) : base(settings) { _client = new MockHttpClient(); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="settings"></param> protected AsyncRestApiComponent(HttpClient client, IHttpClientSettings settings) { _settings = settings; _client = client; Setup(); }
public IdentityHelper(IHttpClientSettings http, IEncryption encryption) { Http = http; Encryption = encryption; }
public ModernHttpClientBuilder(IHttpClientSettings settings) : base(settings) { }
public ServiceHttpClient(IHttpClientSettings settings) { this.BaseAddress = new Uri(settings.ServiceUrl); }
/// <summary> /// Adds in all the services that an application needs /// </summary> /// <param name="services">The existing services collection</param> /// <param name="config">The configuration object for services</param> /// <param name="app">The implementation of IApplicationSettings (It can't be resolved here, so must be passed in to match)</param> /// <param name="env">The implementation of IEnvironmentSettings (It can't be resolved here, so must be passed in to match)</param> /// <param name="http">The implementation of IHttpClientSettings (It can't be resolved here, so must be passed in to match)</param> public static IMvcBuilder AddCommonServices( this IServiceCollection services, ServiceConfiguration config, IApplicationSettings app, IEnvironmentSettings env, IHttpClientSettings http) { if (services == null) { throw new ArgumentNullException(nameof(services)); } // Cors if (!string.IsNullOrWhiteSpace(config.CorsPolicyName)) { services.AddCors(config.Cors); } // Swagger if (config.SwaggerEnabled) { services.AddSwaggerGen(c => { if (!string.IsNullOrWhiteSpace(config.SwaggerVersion) && config.SwaggerInfo != null) { c.SwaggerDoc(config.SwaggerVersion, config.SwaggerInfo(app)); } if (config.SwaggerXmlCommentsLocation != null) { c.IncludeXmlComments(config.SwaggerXmlCommentsLocation(app)); } // ReSharper disable once InvertIf if (!string.IsNullOrWhiteSpace(config.SwaggerSecurityPolicyName) && config.SwaggerSecurityDefinition != null && config.SwaggerSecurityRequirement != null) { c.AddSecurityDefinition(config.SwaggerSecurityPolicyName, config.SwaggerSecurityDefinition(http)); c.AddSecurityRequirement(config.SwaggerSecurityRequirement()); } }); } // Health Check if (!string.IsNullOrWhiteSpace(config.HealthCheckEndpoint)) { services.AddHealthChecks(); } // DI Mapping Registrations services.RegisterCommonServices(config, env); // How to make this abstract/override??? // Web Services if (config.WebServicesEnabled) { services.AddHttpClient(); } // API if (!config.ApiStandardControllerConfiguration) { return(null); } // Controllers var builder = services.AddControllers(); if (config.ApiControllerConfiguration != null) { builder.ConfigureApiBehaviorOptions(config.ApiControllerConfiguration); } if (config.ApiEnableNewtonsoftJson) { if (config.ApiNewtonsoftConfiguration != null) { builder.AddNewtonsoftJson(config.ApiNewtonsoftConfiguration); } else { builder.AddNewtonsoftJson(); // Unsure if we can send null here } } if (config.ApiEnableJsonNet && config.ApiJsonNetConfiguration != null) { builder.AddJsonOptions(config.ApiJsonNetConfiguration); } return(builder); }
protected HttpComputationUnit(HttpClient client, IHttpClientSettings settings) : base(client, settings) { }
public HttpClientBuilder(IHttpClientSettings settings) { Settings = settings; }
protected virtual HttpMessageHandler CreateHandler(Func <HttpClientHandler> httpClientHandler, IHttpClientSettings settings) { var handler = httpClientHandler(); if (handler.SupportsAllowAutoRedirect()) { handler.AllowAutoRedirect = false; //this will be handled by the consuming code } if (handler.SupportsAutomaticDecompression && settings.DecompressionMethods.HasValue) { handler.AutomaticDecompression = settings.DecompressionMethods.Value; } if (settings.ClientCertificateOptions != null) { handler.ClientCertificateOptions = settings.ClientCertificateOptions.Value; } if (settings.CookieContainer != null) { handler.CookieContainer = settings.CookieContainer; handler.UseCookies = true; } if (handler.SupportsPreAuthenticate() && settings.Credentials != null) { handler.Credentials = settings.Credentials; handler.UseDefaultCredentials = true; handler.PreAuthenticate = true; } if (settings.MaxRequestContentBufferSize.HasValue) { handler.MaxRequestContentBufferSize = settings.MaxRequestContentBufferSize.Value; } if (handler.SupportsProxy && settings.Proxy != null) { handler.UseProxy = true; handler.Proxy = settings.Proxy; } return(handler); }