WIP on Ocelot: Change routing and config errors.

This commit is contained in:
Eduard Tomàs 2018-01-30 17:42:00 +00:00
parent dcb9b87361
commit e59829e96b
6 changed files with 27 additions and 8 deletions

View File

@ -34,7 +34,17 @@ namespace OcelotApiGw
{ {
x.Authority = identityUrl; x.Authority = identityUrl;
x.RequireHttpsMetadata = false; x.RequireHttpsMetadata = false;
x.Audience = "ocelot"; 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;
}
};
}); });
services.AddOcelot(_cfg); services.AddOcelot(_cfg);

View File

@ -11,7 +11,7 @@
{ {
"DownstreamPathTemplate": "/{everything}", "DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "purchase-bff", "DownstreamHost": "purchasebff",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/purchase-bff/{everything}", "UpstreamPathTemplate": "/purchase-bff/{everything}",
"UpstreamHttpMethod": [], "UpstreamHttpMethod": [],

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PurchaseBff.Models; using PurchaseBff.Models;
using PurchaseBff.Services; using PurchaseBff.Services;
using System; using System;
@ -9,6 +10,7 @@ using System.Threading.Tasks;
namespace PurchaseBff.Controllers namespace PurchaseBff.Controllers
{ {
[Route("api/v1/[controller]")] [Route("api/v1/[controller]")]
[Authorize]
public class BasketController : Controller public class BasketController : Controller
{ {
private readonly ICatalogService _catalog; private readonly ICatalogService _catalog;

View File

@ -18,12 +18,19 @@ namespace PurchaseBff
} }
public static IWebHost BuildWebHost(string[] args) => public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args) WebHost
.UseStartup<Startup>() .CreateDefaultBuilder(args)
.ConfigureAppConfiguration(cb => .ConfigureAppConfiguration(cb =>
{ {
cb.AddJsonFile("appsettings.localhost.json", optional: true); var sources = cb.Sources;
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource()
{
Optional = true,
Path = "appsettings.localhost.json",
ReloadOnChange = false
});
}) })
.UseStartup<Startup>()
.Build(); .Build();
} }
} }

View File

@ -88,7 +88,7 @@ namespace PurchaseBff
{ {
options.Authority = identityUrl; options.Authority = identityUrl;
options.RequireHttpsMetadata = false; options.RequireHttpsMetadata = false;
options.Audience = "ocelot"; options.Audience = "purchasebff";
options.Events = new JwtBearerEvents() options.Events = new JwtBearerEvents()
{ {
OnAuthenticationFailed = async ctx => OnAuthenticationFailed = async ctx =>

View File

@ -3,7 +3,7 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:55103/", "applicationUrl": "http://localhost:51078/",
"sslPort": 0 "sslPort": 0
} }
}, },