Browse Source

Fix for Campaigns exception and SignalR 401 Unauthorized (#1374)

* update API Gateway - /locations-api/ @ webmarketing/envoy.yaml

* updated signalr services

- envoy: webmarketingapigw
- latest client: webmvc
- service hub: ordering-signalrhub

Co-authored-by: hfz-r <hafiz.roslan@hartalega.com.my>
pull/1416/head
hfz-r 4 years ago
committed by GitHub
parent
commit
85aea20046
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 6 deletions
  1. +13
    -0
      src/ApiGateways/Envoy/config/webmarketing/envoy.yaml
  2. +3
    -0
      src/ApiGateways/Envoy/config/webshopping/envoy.yaml
  3. +18
    -3
      src/Services/Ordering/Ordering.SignalrHub/Startup.cs
  4. +2
    -1
      src/Web/WebMVC/Controllers/AccountController.cs
  5. +1
    -1
      src/Web/WebMVC/Services/LocationService.cs
  6. +1
    -1
      src/Web/WebMVC/libman.json

+ 13
- 0
src/ApiGateways/Envoy/config/webmarketing/envoy.yaml View File

@ -36,6 +36,19 @@ static_resources:
route: route:
auto_host_rewrite: true auto_host_rewrite: true
cluster: marketing cluster: marketing
- name: "l-short"
match:
prefix: "/l/"
route:
auto_host_rewrite: true
prefix_rewrite: "/locations-api/"
cluster: locations
- name: "l-long"
match:
prefix: "/locations-api/"
route:
auto_host_rewrite: true
cluster: locations
http_filters: http_filters:
- name: envoy.router - name: envoy.router
access_log: access_log:


+ 3
- 0
src/ApiGateways/Envoy/config/webshopping/envoy.yaml View File

@ -56,6 +56,9 @@ static_resources:
auto_host_rewrite: true auto_host_rewrite: true
cluster: signalr-hub cluster: signalr-hub
timeout: 300s timeout: 300s
upgrade_configs:
upgrade_type: "websocket"
enabled: true
- name: "b-short" - name: "b-short"
match: match:
prefix: "/b/" prefix: "/b/"


+ 18
- 3
src/Services/Ordering/Ordering.SignalrHub/Startup.cs View File

@ -19,6 +19,7 @@ using Ordering.SignalrHub.IntegrationEvents.EventHandling;
using Ordering.SignalrHub.IntegrationEvents.Events; using Ordering.SignalrHub.IntegrationEvents.Events;
using RabbitMQ.Client; using RabbitMQ.Client;
using System; using System;
using System.Threading.Tasks;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
namespace Ordering.SignalrHub namespace Ordering.SignalrHub
@ -109,7 +110,7 @@ namespace Ordering.SignalrHub
RegisterEventBus(services); RegisterEventBus(services);
services.AddOptions(); services.AddOptions();
//configure autofac //configure autofac
var container = new ContainerBuilder(); var container = new ContainerBuilder();
container.RegisterModule(new ApplicationModule()); container.RegisterModule(new ApplicationModule());
@ -133,7 +134,7 @@ namespace Ordering.SignalrHub
loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase); loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase);
app.UsePathBase(pathBase); app.UsePathBase(pathBase);
} }
app.UseRouting(); app.UseRouting();
app.UseCors("CorsPolicy"); app.UseCors("CorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
@ -150,7 +151,7 @@ namespace Ordering.SignalrHub
{ {
Predicate = r => r.Name.Contains("self") Predicate = r => r.Name.Contains("self")
}); });
endpoints.MapHub<NotificationsHub>("/hub/notificationhub", options => options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransports.All);
endpoints.MapHub<NotificationsHub>("/hub/notificationhub");
}); });
ConfigureEventBus(app); ConfigureEventBus(app);
@ -185,6 +186,20 @@ namespace Ordering.SignalrHub
options.Authority = identityUrl; options.Authority = identityUrl;
options.RequireHttpsMetadata = false; options.RequireHttpsMetadata = false;
options.Audience = "orders.signalrhub"; options.Audience = "orders.signalrhub";
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/hub/notificationhub")))
{
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
}); });
} }


+ 2
- 1
src/Web/WebMVC/Controllers/AccountController.cs View File

@ -20,7 +20,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
} }
[Authorize(AuthenticationSchemes = "OpenIdConnect")] public async Task<IActionResult> SignIn(string returnUrl)
[Authorize(AuthenticationSchemes = "OpenIdConnect")]
public async Task<IActionResult> SignIn(string returnUrl)
{ {
var user = User as ClaimsPrincipal; var user = User as ClaimsPrincipal;
var token = await HttpContext.GetTokenAsync("access_token"); var token = await HttpContext.GetTokenAsync("access_token");


+ 1
- 1
src/Web/WebMVC/Services/LocationService.cs View File

@ -23,7 +23,7 @@ namespace WebMVC.Services
_settings = settings; _settings = settings;
_logger = logger; _logger = logger;
_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/api/v1/l/locations/";
_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/l/api/v1/locations/";
} }
public async Task CreateOrUpdateUserLocation(LocationDTO location) public async Task CreateOrUpdateUserLocation(LocationDTO location)


+ 1
- 1
src/Web/WebMVC/libman.json View File

@ -37,7 +37,7 @@
}, },
{ {
"provider": "unpkg", "provider": "unpkg",
"library": "@microsoft/signalr@3.0.1",
"library": "@microsoft/signalr@latest",
"destination": "wwwroot/lib/@microsoft/signalr/", "destination": "wwwroot/lib/@microsoft/signalr/",
"files": [ "files": [
"dist/browser/signalr.js", "dist/browser/signalr.js",


Loading…
Cancel
Save