// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(mvcOptions => { if (!Configuration.GetValue("DISABLE_AUTH", false)) { // Set Authorized as default policy var policy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .RequireClaim("scope", "uaa.resource") .Build(); mvcOptions.Filters.Add(new AuthorizeFilter(policy)); } }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddDbContext <TimeEntryContext>(options => options.UseMySql(Configuration)); services.AddScoped <ITimeEntryDataGateway, TimeEntryDataGateway>(); services.AddSingleton <IProjectClient>(sp => { var handler = new DiscoveryHttpClientHandler(sp.GetService <IDiscoveryClient>()); var httpClient = new HttpClient(handler, false) { BaseAddress = new Uri(Configuration.GetValue <string>("REGISTRATION_SERVER_ENDPOINT")) }; var contextAccessor = sp.GetService <IHttpContextAccessor>(); var logger = sp.GetService <ILogger <ProjectClient> >(); return(new ProjectClient(httpClient, logger, () => contextAccessor.HttpContext.GetTokenAsync("access_token"))); }); services.AddDiscoveryClient(Configuration); services.AddHystrixMetricsStream(Configuration); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddCloudFoundryJwtBearer(Configuration); }
public ProductService(IHystrixCommandOptions options, IDiscoveryClient client, ILogger <ProductService> logger) : base(options) { _logger = logger; _handler = new DiscoveryHttpClientHandler(client); IsFallbackUserDefined = true; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddDbContext <AllocationContext>(options => options.UseMySql(Configuration)); services.AddScoped <IAllocationDataGateway, AllocationDataGateway>(); services.AddSingleton <IProjectClient>(sp => { var handler = new DiscoveryHttpClientHandler(sp.GetService <IDiscoveryClient>()); var httpClient = new HttpClient(handler, false) { BaseAddress = new Uri(Configuration.GetValue <string>("REGISTRATION_SERVER_ENDPOINT")) }; var logger = sp.GetService <ILogger <ProjectClient> >(); return(new ProjectClient(httpClient, logger)); }); services.AddHystrixMetricsStream(Configuration); // Register the Swagger generator, defining one or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Allocations Server", Version = "v1" }); //c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}/edu.gateway.api.xml"); c.DescribeAllEnumsAsStrings(); }); services.AddDiscoveryClient(Configuration); }
/// <summary> /// Get请求 /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <string> DoGetAsync(this IDiscoveryClient client, string url) { _handler = new DiscoveryHttpClientHandler(client); HttpClient httpClient = new HttpClient(_handler); return(await httpClient.GetStringAsync(url)); }
public Feign(IDiscoveryClient client, ILoggerFactory factory) { Handler = new DiscoveryHttpClientHandler(client, factory.CreateLogger <DiscoveryHttpClientHandler>()); Logger = factory.CreateLogger <TollRateServiceClient>(); Operations = BuildOperations(); }
public AbstractService(IDiscoveryClient client, ILogger logger, IHttpContextAccessor context) { _handler = new DiscoveryHttpClientHandler(client); _handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; _logger = logger; _context = context; }
public TestController(ILogger <TestController> logger, IHttpClientFactory clientFactory, IDiscoveryClient discoveryClient) { _httpClient = clientFactory.CreateClient("CURRRENCY"); _logger = logger; _handler = new DiscoveryHttpClientHandler(discoveryClient); }
/// <summary> /// auth configuration from identity server /// </summary> /// <param name="services">services</param> /// <param name="configuration">configuration</param> public static void ConfigureResourceAuthService(this IServiceCollection services, IConfiguration configuration) { var discoveryClient = services.BuildServiceProvider().GetService <IDiscoveryClient>(); var handler = new DiscoveryHttpClientHandler(discoveryClient); var authority = configuration.GetSection("Identity:Authority").Value; var apiName = configuration.GetSection("Identity:Api").Value; var secret = configuration.GetSection("Identity:Secret").Value; services.AddAuthorization(); services.AddAuthentication(x => { x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddIdentityServerAuthentication(x => { x.ApiName = apiName; x.ApiSecret = secret; x.Authority = authority; x.RequireHttpsMetadata = false; x.JwtBackChannelHandler = handler; x.IntrospectionDiscoveryHandler = handler; x.IntrospectionBackChannelHandler = handler; }); }
/// <summary> /// Get请求 /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static string DoGetSync(this IDiscoveryClient client, string url) { _handler = new DiscoveryHttpClientHandler(client); HttpClient httpClient = new HttpClient(_handler); return(httpClient.GetStringAsync(url).Result); }
public HomeController(IDiscoveryClient client, ILoggerFactory logFactory) { _handler = new DiscoveryHttpClientHandler(client, logFactory.CreateLogger <DiscoveryHttpClientHandler>()); // Remove comment to use SSL communications with Self-Signed Certs // _handler.ServerCertificateCustomValidationCallback = (a,b,c,d) => {return true;}; _logger = logFactory.CreateLogger <HomeController>(); }
public async Task <Response <HttpResponseMessage> > GetResponseAsync(DownstreamContext request) { _handler = new DiscoveryHttpClientHandler(_discoveryClient); var discoveryClientBuilder = new DiscoveryHttpClientBuilder().Create(_handler, request.DownstreamReRoute); var httpDiscoveryClient = discoveryClientBuilder.Client; try { var response = await httpDiscoveryClient.SendAsync(request.DownstreamRequest); return(new OkResponse <HttpResponseMessage>(response)); } catch (TimeoutRejectedException exception) { return (new ErrorResponse <HttpResponseMessage>(new RequestTimedOutError(exception))); } catch (BrokenCircuitException exception) { return (new ErrorResponse <HttpResponseMessage>(new RequestTimedOutError(exception))); } catch (Exception exception) { return(new ErrorResponse <HttpResponseMessage>(new UnableToCompleteRequestError(exception))); } finally { //_cacheHandlers.Set(cacheKey, httpClient, TimeSpan.FromHours(24)); } }
public HttpRpcService(IConfiguration configuration, IDiscoveryClient client, ILogService _LogService) { _handler = new DiscoveryHttpClientHandler(client); httpClient = new HttpClient(_handler); serviceAddress = configuration.GetSection("gateway")["serviceAddress"]; oldWebApi = configuration.GetSection("OldWebApi").Value; logService = _LogService; }
public FlowClient( IDiscoveryClient discoveryClient, ILogger <IFlowClient> logger) { this.discoveryClient = discoveryClient; this.discoveryClientHandler = new DiscoveryHttpClientHandler(this.discoveryClient, logger); this.logger = logger; }
// Lab08 End public FortuneServiceClient(IDiscoveryClient client, IOptionsSnapshot <FortuneServiceConfig> config, ILogger <FortuneServiceClient> logger) { // Lab08 Start _handler = new DiscoveryHttpClientHandler(client); // Lab08 End _logger = logger; _config = config; }
public FrontendController(IDiscoveryClient client, IConfiguration configuration) { string backendName = configuration.GetSection("c2c:backend").Get <string>(); // The .NET Eureka handler automatically replaces the backend app name, so just provide it here: _backendBaseUrl = "http://" + backendName; _handler = new DiscoveryHttpClientHandler(client); }
public FortuneService(IHystrixCommandOptions options, IDiscoveryClient client, ILoggerFactory logFactory) : base(options) { _handler = new DiscoveryHttpClientHandler(client, logFactory.CreateLogger <DiscoveryHttpClientHandler>()); // Remove comment to use SSL communications with Self-Signed Certs // _handler.ServerCertificateCustomValidationCallback = (a,b,c,d) => {return true;}; IsFallbackUserDefined = true; this._logger = logFactory.CreateLogger <FortuneService>(); }
public EurekaService(IDiscoveryClient client) { var handler = new DiscoveryHttpClientHandler(client); this.http = new HttpClient(handler, false) { BaseAddress = new Uri("http://tas-steeltoe-core-eureka-api/app") }; }
public ProductoService(IDiscoveryClient discoveryClient, IConfiguration configuration) { var handler = new DiscoveryHttpClientHandler(discoveryClient); var httpClient = new HttpClient(handler, false) { BaseAddress = new Uri(configuration["urlProductosServicios"]) }; this._productoService = RestClient.For <IProductoService>(httpClient); }
public PricingClient(IConfiguration configuration, IDiscoveryClient discoveryClient) { var handler = new DiscoveryHttpClientHandler(discoveryClient); var httpClient = new HttpClient(handler, false) { BaseAddress = new Uri(configuration.GetValue <string>("PricingServiceUri")) }; client = RestClient.For <IPricingClient>(httpClient); }
public FortuneServiceClient( IOptionsSnapshot <FortuneServiceOptions> config, ILogger <FortuneServiceClient> logger, IDiscoveryClient discoveryClient) { _logger = logger; _config = config; _logger.LogInformation($"FortuneServiceClient URL:{config.Value.RandomFortunePath}"); _discoveryHandler = new DiscoveryHttpClientHandler(discoveryClient, logger); }
public void LookupService_FindsService_ReturnsURI() { // Arrange IDiscoveryClient client = new TestDiscoveryClient(new TestServiceInstance(new Uri("http://foundit:5555"))); DiscoveryHttpClientHandler handler = new DiscoveryHttpClientHandler(client); Uri uri = new Uri("http://foo/test/bar/foo?test=1&test2=2"); // Act and Assert var result = handler.LookupService(uri); Assert.Equal(new Uri("http://foundit:5555/test/bar/foo?test=1&test2=2"), result); }
public void LookupService_NonDefaultPort_ReturnsOriginalURI() { // Arrange IDiscoveryClient client = new TestDiscoveryClient(); DiscoveryHttpClientHandler handler = new DiscoveryHttpClientHandler(client); Uri uri = new Uri("http://foo:8080/test"); // Act and Assert var result = handler.LookupService(uri); Assert.Equal(uri, result); }
public FortuneServiceClient( HttpClient httpClient, IOptions <FortuneServiceOptions> config, ILogger <FortuneServiceClient> logger, IDiscoveryClient client) { _logger = logger; _config = config; _httpClient = httpClient; _handler = new DiscoveryHttpClientHandler(client); }
public JurosClient(IDiscoveryClient discoveryClient, IConfiguration configuration) { var handler = new DiscoveryHttpClientHandler(discoveryClient); var serviceUri = configuration.GetValue <string>("Api1Uri"); var httpClient = new HttpClient(handler, false) { BaseAddress = new Uri(serviceUri) }; client = RestClient.For <IJurosClient>(httpClient); }
public FortuneService( IConfiguration config, IDiscoveryClient client, IConnectionMultiplexer cache, ILogger <FortuneService> logger) { RANDOM_FORTUNE_URL = config["RANDOM_FORTUNE_URL"]; _handler = new DiscoveryHttpClientHandler(client); _logger = logger; _cache = cache; }
public ProductClient(IOptions <ServicesUrl> servicesUrl, IDiscoveryClient discoveryClient) { _servicesUrl = servicesUrl.Value; var handler = new DiscoveryHttpClientHandler(discoveryClient); handler.ServerCertificateCustomValidationCallback = delegate { return(true); }; var httpClient = new HttpClient(handler, false) { BaseAddress = new Uri(_servicesUrl.ProductApiUrl) }; client = RestClient.For <IProductClient>(httpClient); }
public AccountController( IConfiguration configuration, IDiscoveryClient client, SignInManager <Account> signInManager, UserManager <Account> userManager, IPasswordHasher <Account> passwordHasher ) { _configuration = configuration; _handler = new DiscoveryHttpClientHandler(client); _signInManager = signInManager; _signInManager.UserManager = _userManager = userManager; _userManager.PasswordHasher = passwordHasher; }
/// <summary> /// Get请求 /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static string DoPostSync(this IDiscoveryClient client, string url, object content) { _handler = new DiscoveryHttpClientHandler(client); HttpClient httpClient = new HttpClient(_handler); byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content)); using (StreamContent sc = new StreamContent(new MemoryStream(data))) { sc.Headers.ContentLength = data.Length; sc.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = httpClient.PostAsync(url, sc).Result; return(response.Content.ReadAsStringAsync().Result); } }
// Lab07End public FortuneServiceClient( IOptionsSnapshot <FortuneServiceOptions> config, ILogger <FortuneServiceClient> logger, // Lab07 Start IDiscoveryClient client) // Lab07 End { // Lab07 Start _handler = new DiscoveryHttpClientHandler(client, logger); // Lab07 End _logger = logger; _config = config; }
public WingtipToysProductServiceClient( IOptionsSnapshot <WingtipToysProductServiceOptions> config, ILogger <WingtipToysProductServiceClient> logger, IDiscoveryClient client, IHttpContextAccessor context = null) { _handler = new DiscoveryHttpClientHandler(client); _reqContext = context; _logger = logger; _config = config; }