2018-01-11 11:20:38 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-01-11 18:18:16 +01:00
|
|
|
|
using CacheManager.Core;
|
2018-01-11 11:20:38 +01:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2018-01-11 18:18:16 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2018-01-11 11:20:38 +01:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2018-01-11 18:18:16 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Ocelot.DependencyInjection;
|
|
|
|
|
using Ocelot.Middleware;
|
2018-01-11 11:20:38 +01:00
|
|
|
|
|
|
|
|
|
namespace OcelotApiGw
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2018-01-11 18:18:16 +01:00
|
|
|
|
|
|
|
|
|
private readonly IConfiguration _cfg;
|
|
|
|
|
|
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
_cfg = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 11:20:38 +01:00
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2018-01-30 08:50:44 +00:00
|
|
|
|
var identityUrl = _cfg.GetValue<string>("IdentityUrl");
|
|
|
|
|
var authenticationProviderKey = "IdentityApiKey";
|
|
|
|
|
|
|
|
|
|
services.AddAuthentication()
|
|
|
|
|
.AddJwtBearer(authenticationProviderKey, x =>
|
|
|
|
|
{
|
|
|
|
|
x.Authority = identityUrl;
|
|
|
|
|
x.RequireHttpsMetadata = false;
|
|
|
|
|
x.Audience = "ocelot";
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-11 18:18:16 +01:00
|
|
|
|
services.AddOcelot(_cfg);
|
2018-01-11 11:20:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 14:45:46 +01:00
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
2018-01-11 11:20:38 +01:00
|
|
|
|
{
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 14:45:46 +01:00
|
|
|
|
loggerFactory.AddConsole(_cfg.GetSection("Logging"));
|
|
|
|
|
|
|
|
|
|
app.UseOcelot().Wait();
|
2018-01-11 11:20:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|