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";
|
|
|
|
|
|
2018-02-06 17:35:01 +00:00
|
|
|
|
services.AddCors(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddPolicy("CorsPolicy",
|
|
|
|
|
builder => builder.AllowAnyOrigin()
|
|
|
|
|
.AllowAnyMethod()
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
.AllowCredentials());
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-30 08:50:44 +00:00
|
|
|
|
services.AddAuthentication()
|
|
|
|
|
.AddJwtBearer(authenticationProviderKey, x =>
|
|
|
|
|
{
|
|
|
|
|
x.Authority = identityUrl;
|
|
|
|
|
x.RequireHttpsMetadata = false;
|
2018-01-30 17:42:00 +00:00
|
|
|
|
x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
|
|
|
|
|
{
|
2018-02-27 14:32:25 +01:00
|
|
|
|
ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "mobileshoppingagg", "webshoppingagg" }
|
2018-01-30 17:42:00 +00:00
|
|
|
|
};
|
|
|
|
|
x.Events = new Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerEvents()
|
|
|
|
|
{
|
|
|
|
|
OnAuthenticationFailed = async ctx =>
|
2018-01-31 15:35:40 +00:00
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
},
|
|
|
|
|
OnTokenValidated = async ctx =>
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
OnMessageReceived = async ctx =>
|
2018-01-30 17:42:00 +00:00
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-30 08:50:44 +00:00
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-03-14 18:25:26 +01:00
|
|
|
|
var pathBase = _cfg["PATH_BASE"];
|
|
|
|
|
if (!string.IsNullOrEmpty(pathBase))
|
|
|
|
|
{
|
|
|
|
|
app.UsePathBase(pathBase);
|
|
|
|
|
}
|
|
|
|
|
|
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"));
|
|
|
|
|
|
2018-02-06 17:35:01 +00:00
|
|
|
|
app.UseCors("CorsPolicy");
|
|
|
|
|
|
2018-01-18 14:45:46 +01:00
|
|
|
|
app.UseOcelot().Wait();
|
2018-01-11 11:20:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|