75 lines
2.3 KiB
C#
Raw Normal View History

2018-01-11 11:20:38 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CacheManager.Core;
2018-01-11 11:20:38 +01:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
2018-01-11 11:20:38 +01:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
2018-01-11 11:20:38 +01:00
namespace OcelotApiGw
{
public class Startup
{
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.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "purchasebff" }
};
x.Events = new Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerEvents()
{
OnAuthenticationFailed = async ctx =>
{
int i = 0;
},
OnTokenValidated = async ctx =>
{
int i = 0;
},
OnMessageReceived = async ctx =>
{
int i = 0;
}
};
2018-01-30 08:50:44 +00: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
}
}
}