Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix for Campaigns exception and SignalR 401 Unauthorized (#1374)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
hfz-r and hfz-r authored Aug 27, 2020
1 parent df2c2bb commit 85aea20
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/ApiGateways/Envoy/config/webmarketing/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ static_resources:
route:
auto_host_rewrite: true
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:
- name: envoy.router
access_log:
Expand Down
3 changes: 3 additions & 0 deletions src/ApiGateways/Envoy/config/webshopping/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ static_resources:
auto_host_rewrite: true
cluster: signalr-hub
timeout: 300s
upgrade_configs:
upgrade_type: "websocket"
enabled: true
- name: "b-short"
match:
prefix: "/b/"
Expand Down
21 changes: 18 additions & 3 deletions src/Services/Ordering/Ordering.SignalrHub/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Ordering.SignalrHub.IntegrationEvents.Events;
using RabbitMQ.Client;
using System;
using System.Threading.Tasks;
using System.IdentityModel.Tokens.Jwt;

namespace Ordering.SignalrHub
Expand Down Expand Up @@ -109,7 +110,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
RegisterEventBus(services);

services.AddOptions();

//configure autofac
var container = new ContainerBuilder();
container.RegisterModule(new ApplicationModule());
Expand All @@ -133,7 +134,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase);
app.UsePathBase(pathBase);
}

app.UseRouting();
app.UseCors("CorsPolicy");
app.UseAuthentication();
Expand All @@ -150,7 +151,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
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);
Expand Down Expand Up @@ -185,6 +186,20 @@ private void ConfigureAuthService(IServiceCollection services)
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
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;
}
};
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/Web/WebMVC/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public AccountController(ILogger<AccountController> 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 token = await HttpContext.GetTokenAsync("access_token");
Expand Down
2 changes: 1 addition & 1 deletion src/Web/WebMVC/Services/LocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LocationService(HttpClient httpClient, IOptions<AppSettings> settings, IL
_settings = settings;
_logger = logger;

_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/api/v1/l/locations/";
_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/l/api/v1/locations/";
}

public async Task CreateOrUpdateUserLocation(LocationDTO location)
Expand Down
2 changes: 1 addition & 1 deletion src/Web/WebMVC/libman.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
{
"provider": "unpkg",
"library": "@microsoft/signalr@3.0.1",
"library": "@microsoft/signalr@latest",
"destination": "wwwroot/lib/@microsoft/signalr/",
"files": [
"dist/browser/signalr.js",
Expand Down

0 comments on commit 85aea20

Please sign in to comment.