├── WebApiA ├── appsettings.Development.json ├── appsettings.json ├── Controllers │ ├── TimeController.cs │ ├── SlowController.cs │ ├── CounterController.cs │ ├── UserController.cs │ └── ValuesController.cs ├── WebApiA.csproj ├── Program.cs ├── Properties │ └── launchSettings.json └── Startup.cs ├── WebApiB ├── appsettings.Development.json ├── appsettings.json ├── Controllers │ ├── CounterController.cs │ └── ValuesController.cs ├── WebApiB.csproj ├── Program.cs ├── Properties │ └── launchSettings.json └── Startup.cs ├── OcelotGetway ├── appsettings.Development.json ├── appsettings.json ├── Program.cs ├── Properties │ └── launchSettings.json ├── Controllers │ └── ValuesController.cs ├── OcelotGetway.csproj ├── MyCache.cs ├── Startup.cs └── configuration.json ├── IdentityServer ├── appsettings.Development.json ├── appsettings.json ├── IdentityServer.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── Controllers │ ├── TokenController.cs │ └── ValuesController.cs ├── Config.cs ├── Startup.cs └── tempkey.rsa ├── OcelotDemo.sln ├── .gitattributes └── .gitignore /WebApiA/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WebApiB/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /OcelotGetway/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /IdentityServer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WebApiA/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiB/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IdentityServer/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /OcelotGetway/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApiA/Controllers/TimeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace WebApiA.Controllers 5 | { 6 | [Produces("application/json")] 7 | [Route("api/[controller]/[action]")] 8 | public class TimeController : Controller 9 | { 10 | [HttpGet] 11 | public string GetNow() 12 | { 13 | return DateTime.Now.ToString("hh:mm:ss"); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /WebApiA/Controllers/SlowController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace WebApiA.Controllers 5 | { 6 | public class SlowController : Controller 7 | { 8 | [Produces("application/json")] 9 | [Route("api/[controller]/[action]")] 10 | public async Task GetName() 11 | { 12 | await Task.Delay(6000); 13 | return "Jonathan"; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /WebApiA/Controllers/CounterController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace WebApiA.Controllers 4 | { 5 | [Produces("application/json")] 6 | [Route("api/[controller]/[action]")] 7 | public class CounterController : Controller 8 | { 9 | private static int _count = 0; 10 | 11 | [HttpGet] 12 | public string Count() 13 | { 14 | return $"Count {++_count} from WebapiA"; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /WebApiB/Controllers/CounterController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace WebApiB.Controllers 4 | { 5 | [Produces("application/json")] 6 | [Route("api/[controller]/[action]")] 7 | public class CounterController : Controller 8 | { 9 | private static int _count = 0; 10 | 11 | [HttpGet] 12 | public string Count() 13 | { 14 | return $"Count {++_count} from WebapiB"; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /WebApiA/WebApiA.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /WebApiB/WebApiB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /WebApiA/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace WebApiA.Controllers 4 | { 5 | [Produces("application/json")] 6 | [Route("api/[controller]/[action]")] 7 | public class UserController : Controller 8 | { 9 | [HttpGet] 10 | public string GetSex(string name) 11 | { 12 | if (name == "Jonathan") 13 | return "Man"; 14 | return null; 15 | } 16 | 17 | [HttpGet] 18 | public int? GetAge(string name) 19 | { 20 | if (name == "Jonathan") 21 | return 24; 22 | return null; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /WebApiA/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiA 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WebApiB/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApiB 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /OcelotGetway/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace OcelotGetway 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /IdentityServer/IdentityServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /IdentityServer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace IdentityServer 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WebApiA/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5001/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": false, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "WebApiA": { 20 | "commandName": "Project", 21 | "launchBrowser": false, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:5001/" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /WebApiB/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5002/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": false, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "WebApiB": { 20 | "commandName": "Project", 21 | "launchBrowser": false, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:5002/" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /OcelotGetway/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5000/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": false, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "OcelotGetway": { 20 | "commandName": "Project", 21 | "launchBrowser": false, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:5000/" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /IdentityServer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:6000/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": false, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "IdentityServer": { 20 | "commandName": "Project", 21 | "launchBrowser": false, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:6000/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /IdentityServer/Controllers/TokenController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using IdentityModel.Client; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace IdentityServer.Controllers 8 | { 9 | [Produces("application/json")] 10 | [Route("api/Token")] 11 | public class TokenController : Controller 12 | { 13 | public async Task Get() 14 | { 15 | var disco = await DiscoveryClient.GetAsync($"{Request.Scheme}://{Request.Host}"); 16 | if(disco.IsError) 17 | { 18 | Console.WriteLine(disco.Error); 19 | return null; 20 | } 21 | 22 | var tokenClient = new TokenClient(disco.TokenEndpoint, "client", "secret"); 23 | var tokenResponse = await tokenClient.RequestClientCredentialsAsync("api1"); 24 | if(tokenResponse.IsError) 25 | { 26 | Console.WriteLine(tokenResponse.Error); 27 | return null; 28 | } 29 | 30 | return tokenResponse.Json; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /IdentityServer/Config.cs: -------------------------------------------------------------------------------- 1 | using IdentityServer4.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace IdentityServer 8 | { 9 | public class Config 10 | { 11 | public static IEnumerable GetApiResources() 12 | { 13 | return new List() 14 | { 15 | new ApiResource("api1", "My Api") 16 | }; 17 | } 18 | 19 | public static IEnumerable GetClients() 20 | { 21 | return new List() 22 | { 23 | new Client() 24 | { 25 | ClientId = "client", 26 | AllowedGrantTypes = GrantTypes.ClientCredentials, 27 | ClientSecrets = 28 | { 29 | new Secret("secret".Sha256()) 30 | }, 31 | AllowedScopes = 32 | { 33 | "api1" 34 | } 35 | } 36 | }; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /OcelotGetway/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace OcelotGetway.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /IdentityServer/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace IdentityServer.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /OcelotGetway/OcelotGetway.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Always 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /WebApiA/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace WebApiA.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | var headers = Request.Headers.Select(x => $"{x.Key}:{x.Value}"); 17 | 18 | return headers; 19 | } 20 | 21 | // GET api/values/5 22 | [HttpGet("{id}")] 23 | public string Get(int id) 24 | { 25 | return $"value {id} from WebApiA"; 26 | } 27 | 28 | // POST api/values 29 | [HttpPost] 30 | public void Post([FromBody]string value) 31 | { 32 | } 33 | 34 | // PUT api/values/5 35 | [HttpPut("{id}")] 36 | public void Put(int id, [FromBody]string value) 37 | { 38 | } 39 | 40 | // DELETE api/values/5 41 | [HttpDelete("{id}")] 42 | public void Delete(int id) 43 | { 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WebApiB/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace WebApiB.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | var headers = Request.Headers.Select(x => $"{x.Key}:{x.Value}"); 17 | 18 | return headers; 19 | } 20 | 21 | // GET api/values/5 22 | [HttpGet("{id}")] 23 | public string Get(int id) 24 | { 25 | return $"value {id} from WebApiB"; 26 | } 27 | 28 | // POST api/values 29 | [HttpPost] 30 | public void Post([FromBody]string value) 31 | { 32 | } 33 | 34 | // PUT api/values/5 35 | [HttpPut("{id}")] 36 | public void Put(int id, [FromBody]string value) 37 | { 38 | } 39 | 40 | // DELETE api/values/5 41 | [HttpDelete("{id}")] 42 | public void Delete(int id) 43 | { 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WebApiA/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | 12 | namespace WebApiA 13 | { 14 | public class Startup 15 | { 16 | public Startup(IConfiguration configuration) 17 | { 18 | Configuration = configuration; 19 | } 20 | 21 | public IConfiguration Configuration { get; } 22 | 23 | // This method gets called by the runtime. Use this method to add services to the container. 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | services.AddMvc(); 27 | } 28 | 29 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 30 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 31 | { 32 | if (env.IsDevelopment()) 33 | { 34 | app.UseDeveloperExceptionPage(); 35 | } 36 | 37 | app.UseMvc(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WebApiB/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | 12 | namespace WebApiB 13 | { 14 | public class Startup 15 | { 16 | public Startup(IConfiguration configuration) 17 | { 18 | Configuration = configuration; 19 | } 20 | 21 | public IConfiguration Configuration { get; } 22 | 23 | // This method gets called by the runtime. Use this method to add services to the container. 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | services.AddMvc(); 27 | } 28 | 29 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 30 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 31 | { 32 | if (env.IsDevelopment()) 33 | { 34 | app.UseDeveloperExceptionPage(); 35 | } 36 | 37 | app.UseMvc(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /IdentityServer/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | 12 | namespace IdentityServer 13 | { 14 | public class Startup 15 | { 16 | public Startup(IConfiguration configuration) 17 | { 18 | Configuration = configuration; 19 | } 20 | 21 | public IConfiguration Configuration { get; } 22 | 23 | // This method gets called by the runtime. Use this method to add services to the container. 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | services.AddMvc(); 27 | 28 | services 29 | .AddIdentityServer() 30 | .AddDeveloperSigningCredential() 31 | .AddInMemoryApiResources(Config.GetApiResources()) 32 | .AddInMemoryClients(Config.GetClients()); 33 | } 34 | 35 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 36 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 37 | { 38 | if (env.IsDevelopment()) 39 | { 40 | app.UseDeveloperExceptionPage(); 41 | } 42 | 43 | app.UseIdentityServer(); 44 | 45 | app.UseMvc(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /IdentityServer/tempkey.rsa: -------------------------------------------------------------------------------- 1 | {"KeyId":"340bccab41985f3150c01c0bc6ef199a","Parameters":{"D":"VmqB8kEunnnz+cgcFsDfQpwZrrQ8SX0csVkYxWjr0OzQX1E5n/8pVt3g2zOB45b3Wa1nxkz61sZGZxAQceGQprMqGc0Kn+X1t0Z1gSe9QKuFaWXKvkrQth0OZ6kTB4iXdfnOeOGjhkPXwPiYTVoa+hMEX5t4ha67rgV6NTzhLwDvQHOYVzBgMuglfcevBzKm8nspd/5QSmIL7tSzqGakGJInQ1wvHjQJPZ2n4Dxwoa3JSWUnTgFIizYrXN2JvudpQU3lqsJ+0pWZU6whV3f3583b67G7Vi5XUpODUFF74PO/d16cmthti3CdC8MBMKFYCGPkNAVngAeHQLDfAKRixQ==","DP":"u1Vaxhpg8yRFkxtMDQ5SmM8OjE3ojLMQN/X4Ocjscy6OhRRtB5nmOilUV7jgwpBBT+EeIMSMTEfDH11aXmpOIy90mmesIJG2jVZKdYc52Z4Gz8nlTfaqqWQ8h5pa6w+VNqlhfBhHvTnKq2gmfUcLullPFANvlKIRQDurkZ85fMM=","DQ":"i6u6gu4fbRzFsCQDtCxF+dHAKI0YPNz+F9OeEy2chgtoY93qeATVnyp9cJHXxP3K+F1K57MZ4ucMqOcSBSjq8ATSl6twfpJl7LEv3rYtaJnsoarYlPf8NIHqHyrdBGRr3ENQdPuJHSBP+wRr2qElahxd2W9XNWLlzkY/kJIUfvM=","Exponent":"AQAB","InverseQ":"JS9zM2kUnSfQOTwUOACTAQPb0S9kNETn3yJFc2EygFDiiT0aDtiWZreZcdEdzVVkeWa/fA7oClBXeoe7CWHSUpgDsHC7ViXqL6LYUxO+aL9HFR5t+Drm/tjCg6RNEGrH4l+pjfL34O57Wbp7fnjCmGnauVe65EnDfH5QGMLPEPw=","Modulus":"yzd+tQt2d3CAyG+IgA8xiNEut6R2jMIZLGSo0mhq3df65NVzYEiwynLWuDdPCSqHpNjDJCKDMJgXavR3ng+MHSwp5XHvkOS9+XFjTfQGgeBdX42LuftE8r4iFgXZORYjR2BatQ3F9ohkNOB6CuE4ppNrGnaEThKffcrQ7d4zM2cdfhQFU2/p27mfYi3kRu8Gyo61q9uSEN728gUMDWbwCwwNIcciS14gAhefVfhn/p3+00jYeCR/Ege9URN+KbwIniliZfL3LdRoTWOZtopXj0YeagkXgt3TruQ8ip+SYa7WYcHfLA+3zMMRPe/eYrKbe0Es1E7Bsrz0Gie9JfDoCQ==","P":"2YgbvSolxcYnGv82IyCiTsJglXx5Ar4Q815TA68NzZoa13VI1SUP03AGUZZz1aO7EtI/KC1htgCIU3+bP4l4nGwUa3u1jvJ+I2SHDyvKf6qChfvXTbQwtyvt9vNOdE1PhPsWm+NCjXZtM7VGjYkCsjNvJf/TZ1R/in0kzi1T088=","Q":"7ydV/2b7+aJJdWMFc8v6cv/K4edaCGVBiDi0NIrSwBrZrVU7p1wynjxft/leCdDRymaOPjPYlA/BSfPHmsiPaAl9AOc1AYY08/Yoi21xmE+1KsF1RGSg9DIZwfpenBPhNgRaMFt8MEzRQ23IfjRDhYGnthZbaLi6sg9bB0gFhKc="}} -------------------------------------------------------------------------------- /OcelotGetway/MyCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Ocelot.Cache; 5 | 6 | namespace OcelotGetway 7 | { 8 | public class MyCache : IOcelotCache 9 | { 10 | private static Dictionary _cacheObjs = new Dictionary(); 11 | 12 | public void Add(string key, CachedResponse value, TimeSpan ttl, string region) 13 | { 14 | if (!_cacheObjs.ContainsKey($"{region}_{key}")) 15 | { 16 | _cacheObjs.Add($"{region}_{key}", new CacheObj() 17 | { 18 | ExpireTime = DateTime.Now.Add(ttl), 19 | Response = value 20 | }); 21 | } 22 | } 23 | 24 | public CachedResponse Get(string key, string region) 25 | { 26 | if (!_cacheObjs.ContainsKey($"{region}_{key}")) return null; 27 | 28 | var cacheObj = _cacheObjs[$"{region}_{key}"]; 29 | if (cacheObj != null && cacheObj.ExpireTime >= DateTime.Now) 30 | { 31 | return cacheObj.Response; 32 | } 33 | 34 | _cacheObjs.Remove($"{region}_{key}"); 35 | return null; 36 | 37 | } 38 | 39 | public void ClearRegion(string region) 40 | { 41 | var keysToRemove = _cacheObjs.Where(c => c.Key.StartsWith($"{region}_")) 42 | .Select(c => c.Key) 43 | .ToList(); 44 | foreach (var key in keysToRemove) 45 | { 46 | _cacheObjs.Remove(key); 47 | } 48 | 49 | } 50 | 51 | public void AddAndDelete(string key, CachedResponse value, TimeSpan ttl, string region) 52 | { 53 | if (_cacheObjs.ContainsKey($"{region}_{key}")) 54 | { 55 | _cacheObjs.Remove($"{region}_{key}"); 56 | } 57 | 58 | _cacheObjs.Add($"{region}_{key}", new CacheObj() 59 | { 60 | ExpireTime = DateTime.Now.Add(ttl), 61 | Response = value 62 | }); 63 | } 64 | } 65 | 66 | public class CacheObj 67 | { 68 | public DateTime ExpireTime { get; set; } 69 | 70 | public CachedResponse Response { get; set; } 71 | } 72 | } -------------------------------------------------------------------------------- /OcelotGetway/Startup.cs: -------------------------------------------------------------------------------- 1 | using IdentityServer4.AccessTokenValidation; 2 | using Microsoft.AspNetCore.Authentication.JwtBearer; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Ocelot.Administration; 9 | using Ocelot.Cache; 10 | using Ocelot.Cache.CacheManager; 11 | using Ocelot.DependencyInjection; 12 | using Ocelot.Middleware; 13 | using Ocelot.Provider.Consul; 14 | using Ocelot.Provider.Polly; 15 | 16 | namespace OcelotGetway 17 | { 18 | public class Startup 19 | { 20 | public Startup(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | } 24 | 25 | public IConfiguration Configuration { get; } 26 | 27 | // This method gets called by the runtime. Use this method to add services to the container. 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | services.AddMvc(); 31 | 32 | void options(IdentityServerAuthenticationOptions o) 33 | { 34 | o.Authority = "http://localhost:6000"; 35 | o.RequireHttpsMetadata = false; 36 | o.ApiName = "api1"; 37 | } 38 | 39 | services 40 | .AddOcelot(new ConfigurationBuilder() 41 | .AddJsonFile("configuration.json") 42 | .Build()) 43 | .AddConsul() 44 | .AddPolly() 45 | .AddCacheManager(x => x.WithDictionaryHandle()) 46 | .AddAdministration("/administration", "secret"); 47 | // .AddAdministration("/administration", options); 48 | 49 | services 50 | .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 51 | .AddIdentityServerAuthentication("TestKey", options); 52 | 53 | services.AddSingleton, MyCache>(); 54 | } 55 | 56 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 57 | public async void Configure(IApplicationBuilder app, IHostingEnvironment env) 58 | { 59 | if (env.IsDevelopment()) 60 | { 61 | app.UseDeveloperExceptionPage(); 62 | } 63 | 64 | await app.UseOcelot(); 65 | 66 | app.UseAuthentication(); 67 | 68 | app.UseMvc(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /OcelotDemo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.2027 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OcelotGetway", "OcelotGetway\OcelotGetway.csproj", "{2A6D20E0-2804-4F43-8CDF-F9F10E935E2E}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiA", "WebApiA\WebApiA.csproj", "{8F3A9505-2C05-4CAF-8AEA-767C2F94FA21}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiB", "WebApiB\WebApiB.csproj", "{F697657C-3319-42C6-BA78-69DBC862EBDB}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer", "IdentityServer\IdentityServer.csproj", "{EB7EF214-CAE4-4D9F-B620-8D0652970489}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {2A6D20E0-2804-4F43-8CDF-F9F10E935E2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {2A6D20E0-2804-4F43-8CDF-F9F10E935E2E}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {2A6D20E0-2804-4F43-8CDF-F9F10E935E2E}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {2A6D20E0-2804-4F43-8CDF-F9F10E935E2E}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {8F3A9505-2C05-4CAF-8AEA-767C2F94FA21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {8F3A9505-2C05-4CAF-8AEA-767C2F94FA21}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {8F3A9505-2C05-4CAF-8AEA-767C2F94FA21}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {8F3A9505-2C05-4CAF-8AEA-767C2F94FA21}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {F697657C-3319-42C6-BA78-69DBC862EBDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {F697657C-3319-42C6-BA78-69DBC862EBDB}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {F697657C-3319-42C6-BA78-69DBC862EBDB}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {F697657C-3319-42C6-BA78-69DBC862EBDB}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {EB7EF214-CAE4-4D9F-B620-8D0652970489}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {EB7EF214-CAE4-4D9F-B620-8D0652970489}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {EB7EF214-CAE4-4D9F-B620-8D0652970489}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {EB7EF214-CAE4-4D9F-B620-8D0652970489}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {C144C418-94B8-405B-9C06-30348A922C67} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | *.rsa 10 | 11 | # User-specific files (MonoDevelop/Xamarin Studio) 12 | *.userprefs 13 | 14 | # Build results 15 | [Dd]ebug/ 16 | [Dd]ebugPublic/ 17 | [Rr]elease/ 18 | [Rr]eleases/ 19 | x64/ 20 | x86/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | [Ll]og/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | project.fragment.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | *.VC.db 86 | *.VC.VC.opendb 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # DocProject is a documentation generator add-in 130 | DocProject/buildhelp/ 131 | DocProject/Help/*.HxT 132 | DocProject/Help/*.HxC 133 | DocProject/Help/*.hhc 134 | DocProject/Help/*.hhk 135 | DocProject/Help/*.hhp 136 | DocProject/Help/Html2 137 | DocProject/Help/html 138 | 139 | # Click-Once directory 140 | publish/ 141 | 142 | # Publish Web Output 143 | *.[Pp]ublish.xml 144 | *.azurePubxml 145 | # TODO: Comment the next line if you want to checkin your web deploy settings 146 | # but database connection strings (with potential passwords) will be unencrypted 147 | #*.pubxml 148 | *.publishproj 149 | 150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 151 | # checkin your Azure Web App publish settings, but sensitive information contained 152 | # in these scripts will be unencrypted 153 | PublishScripts/ 154 | 155 | # NuGet Packages 156 | *.nupkg 157 | # The packages folder can be ignored because of Package Restore 158 | **/packages/* 159 | # except build/, which is used as an MSBuild target. 160 | !**/packages/build/ 161 | # Uncomment if necessary however generally it will be regenerated when needed 162 | #!**/packages/repositories.config 163 | # NuGet v3's project.json files produces more ignoreable files 164 | *.nuget.props 165 | *.nuget.targets 166 | 167 | # Microsoft Azure Build Output 168 | csx/ 169 | *.build.csdef 170 | 171 | # Microsoft Azure Emulator 172 | ecf/ 173 | rcf/ 174 | 175 | # Windows Store app package directories and files 176 | AppPackages/ 177 | BundleArtifacts/ 178 | Package.StoreAssociation.xml 179 | _pkginfo.txt 180 | 181 | # Visual Studio cache files 182 | # files ending in .cache can be ignored 183 | *.[Cc]ache 184 | # but keep track of directories ending in .cache 185 | !*.[Cc]ache/ 186 | 187 | # Others 188 | ClientBin/ 189 | ~$* 190 | *~ 191 | *.dbmdl 192 | *.dbproj.schemaview 193 | *.jfm 194 | *.pfx 195 | *.publishsettings 196 | node_modules/ 197 | orleans.codegen.cs 198 | 199 | # Since there are multiple workflows, uncomment next line to ignore bower_components 200 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 201 | #bower_components/ 202 | 203 | # RIA/Silverlight projects 204 | Generated_Code/ 205 | 206 | # Backup & report files from converting an old project file 207 | # to a newer Visual Studio version. Backup files are not needed, 208 | # because we have git ;-) 209 | _UpgradeReport_Files/ 210 | Backup*/ 211 | UpgradeLog*.XML 212 | UpgradeLog*.htm 213 | 214 | # SQL Server files 215 | *.mdf 216 | *.ldf 217 | 218 | # Business Intelligence projects 219 | *.rdl.data 220 | *.bim.layout 221 | *.bim_*.settings 222 | 223 | # Microsoft Fakes 224 | FakesAssemblies/ 225 | 226 | # GhostDoc plugin setting file 227 | *.GhostDoc.xml 228 | 229 | # Node.js Tools for Visual Studio 230 | .ntvs_analysis.dat 231 | 232 | # Visual Studio 6 build log 233 | *.plg 234 | 235 | # Visual Studio 6 workspace options file 236 | *.opt 237 | 238 | # Visual Studio LightSwitch build output 239 | **/*.HTMLClient/GeneratedArtifacts 240 | **/*.DesktopClient/GeneratedArtifacts 241 | **/*.DesktopClient/ModelManifest.xml 242 | **/*.Server/GeneratedArtifacts 243 | **/*.Server/ModelManifest.xml 244 | _Pvt_Extensions 245 | 246 | # Paket dependency manager 247 | .paket/paket.exe 248 | paket-files/ 249 | 250 | # FAKE - F# Make 251 | .fake/ 252 | 253 | # JetBrains Rider 254 | .idea/ 255 | *.sln.iml 256 | 257 | # CodeRush 258 | .cr/ 259 | 260 | # Python Tools for Visual Studio (PTVS) 261 | __pycache__/ 262 | *.pyc 263 | -------------------------------------------------------------------------------- /OcelotGetway/configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "ReRoutes": [ 3 | { 4 | "DownstreamPathTemplate": "/api/values", 5 | "DownstreamScheme": "http", 6 | "DownstreamHostAndPorts": [ 7 | { 8 | "Host": "localhost", 9 | "Port": 5001 10 | } 11 | ], 12 | "UpstreamPathTemplate": "/webapia/values", 13 | "UpstreamHttpMethod": [ "Get" ], 14 | "AuthenticationOptions": { 15 | "AuthenticationProviderKey": "TestKey", 16 | "AllowScopes": [] 17 | } 18 | }, 19 | { 20 | "DownstreamPathTemplate": "/api/values", 21 | "DownstreamScheme": "http", 22 | "DownstreamHostAndPorts": [ 23 | { 24 | "Host": "localhost", 25 | "Port": 5002 26 | } 27 | ], 28 | "UpstreamPathTemplate": "/webapib/values", 29 | "UpstreamHttpMethod": [ "Get" ], 30 | "RateLimitOptions": { 31 | "ClientWhiteList": [ 32 | "myclient" 33 | ], 34 | "EnableRateLimiting": true, 35 | "Period": "1m", 36 | "PeriodTimespan": 30, 37 | "Limit": 2 38 | } 39 | }, 40 | { 41 | "DownstreamPathTemplate": "/api/values/{id}", 42 | "DownstreamScheme": "http", 43 | "DownstreamHostAndPorts": [ 44 | { 45 | "Host": "localhost", 46 | "Port": 5001 47 | } 48 | ], 49 | "UpstreamPathTemplate": "/WebApiA/values/{id}", 50 | "UpstreamHttpMethod": [ "Get" ], 51 | "ReRouteIsCaseSensitive": true 52 | }, 53 | { 54 | "DownstreamPathTemplate": "/api/values/{id}", 55 | "DownstreamScheme": "http", 56 | "DownstreamHostAndPorts": [ 57 | { 58 | "Host": "localhost", 59 | "Port": 5002 60 | } 61 | ], 62 | "UpstreamPathTemplate": "/WebApib/values/{id}", 63 | "UpstreamHttpMethod": [ "Get" ] 64 | }, 65 | { 66 | "DownstreamPathTemplate": "/api/User/GetSex", 67 | "DownstreamScheme": "http", 68 | "DownstreamHostAndPorts": [ 69 | { 70 | "Host": "localhost", 71 | "Port": 5001 72 | } 73 | ], 74 | "UpstreamPathTemplate": "/Sex", 75 | "UpstreamHttpMethod": [ "Get" ], 76 | "Key": "Sex" 77 | }, 78 | { 79 | "DownstreamPathTemplate": "/api/User/GetAge", 80 | "DownstreamScheme": "http", 81 | "DownstreamHostAndPorts": [ 82 | { 83 | "Host": "localhost", 84 | "Port": 5001 85 | } 86 | ], 87 | "UpstreamPathTemplate": "/Age", 88 | "UpstreamHttpMethod": [ "Get" ], 89 | "Key": "Age" 90 | }, 91 | { 92 | "DownstreamPathTemplate": "/api/User/GetID", 93 | "DownstreamScheme": "http", 94 | "DownstreamHostAndPorts": [ 95 | { 96 | "Host": "localhost", 97 | "Port": 5001 98 | } 99 | ], 100 | "UpstreamPathTemplate": "/ID", 101 | "UpstreamHttpMethod": [ "Get" ], 102 | "Key": "ID" 103 | }, 104 | { 105 | "DownstreamPathTemplate": "/api/Counter/Count", 106 | "DownstreamScheme": "http", 107 | "UpstreamPathTemplate": "/count", 108 | "UpstreamHttpMethod": [ "Get" ], 109 | "ServiceName": "Count", 110 | "LoadBalancerOptions": { 111 | "Type": "RoundRobin" 112 | } 113 | }, 114 | { 115 | "DownstreamPathTemplate": "/api/Token", 116 | "DownstreamScheme": "http", 117 | "DownstreamHostAndPorts": [ 118 | { 119 | "Host": "localhost", 120 | "Port": 6000 121 | } 122 | ], 123 | "UpstreamPathTemplate": "/GetToken", 124 | "UpstreamHttpMethod": [ "Get" ] 125 | }, 126 | { 127 | "DownstreamPathTemplate": "/api/Time/GetNow", 128 | "DownstreamScheme": "http", 129 | "DownstreamHostAndPorts": [ 130 | { 131 | "Host": "localhost", 132 | "Port": 5001 133 | } 134 | ], 135 | "UpstreamPathTemplate": "/Now", 136 | "UpstreamHttpMethod": [ "Get" ], 137 | "FileCacheOptions": { 138 | "TtlSeconds": 60, 139 | "Region": "somename" 140 | } 141 | }, 142 | { 143 | "DownstreamPathTemplate": "/api/Slow/GetName", 144 | "DownstreamScheme": "http", 145 | "DownstreamHostAndPorts": [ 146 | { 147 | "Host": "localhost", 148 | "Port": 5001 149 | } 150 | ], 151 | "UpstreamPathTemplate": "/GetName", 152 | "UpstreamHttpMethod": [ "Get" ], 153 | "QoSOptions": { 154 | "ExceptionsAllowedBeforeBreaking":3, 155 | "DurationOfBreak":60000, 156 | "TimeoutValue": 1000 157 | } 158 | }, 159 | { 160 | "DownstreamPathTemplate": "/api/Values", 161 | "DownstreamScheme": "http", 162 | "DownstreamHostAndPorts": [ 163 | { 164 | "Host": "localhost", 165 | "Port": 5001 166 | }, 167 | { 168 | "Host": "localhost", 169 | "Port": 5002 170 | } 171 | ], 172 | "DownstreamHeaderTransform": { 173 | "Name": "Jonathan", 174 | "Server": "Kestrel, Nginx", 175 | "X-Forwarded-For": "{RemoteIpAddress}", 176 | "Location": "{DownstreamBaseUrl}, {BaseUrl}" 177 | }, 178 | "UpstreamPathTemplate": "/RequestHeader", 179 | "UpstreamHttpMethod": [ 180 | "Get" 181 | ], 182 | "UpstreamHeaderTransform": { 183 | "Uncle": "Bob", 184 | "User-Agent": "PostmanRuntime/7.11.0, postman" 185 | }, 186 | "LoadBalancerOptions": { 187 | "Type": "RoundRobin" 188 | } 189 | } 190 | ], 191 | "Aggregates": [ 192 | { 193 | "ReRouteKeys": [ 194 | "Sex", 195 | "Age", 196 | "ID" 197 | ], 198 | "UpstreamPathTemplate": "/GetUserInfo" 199 | } 200 | ], 201 | "GlobalConfiguration": { 202 | "ServiceDiscoveryProvider": { 203 | "Host": "localhost", 204 | "Port": 8500 205 | }, 206 | "RateLimitOptions": { 207 | "DisableRateLimitHeaders": false, 208 | "QuotaExceededMessage": "Stop request plz!", 209 | "HttpStatusCode": 999, 210 | "ClientIdHeader": "cid" 211 | } 212 | } 213 | } --------------------------------------------------------------------------------