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

Commit 85aea20

Browse files
hfz-rhfz-r
andauthored
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 <[email protected]>
1 parent df2c2bb commit 85aea20

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

src/ApiGateways/Envoy/config/webmarketing/envoy.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ static_resources:
3636
route:
3737
auto_host_rewrite: true
3838
cluster: marketing
39+
- name: "l-short"
40+
match:
41+
prefix: "/l/"
42+
route:
43+
auto_host_rewrite: true
44+
prefix_rewrite: "/locations-api/"
45+
cluster: locations
46+
- name: "l-long"
47+
match:
48+
prefix: "/locations-api/"
49+
route:
50+
auto_host_rewrite: true
51+
cluster: locations
3952
http_filters:
4053
- name: envoy.router
4154
access_log:

src/ApiGateways/Envoy/config/webshopping/envoy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ static_resources:
5656
auto_host_rewrite: true
5757
cluster: signalr-hub
5858
timeout: 300s
59+
upgrade_configs:
60+
upgrade_type: "websocket"
61+
enabled: true
5962
- name: "b-short"
6063
match:
6164
prefix: "/b/"

src/Services/Ordering/Ordering.SignalrHub/Startup.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Ordering.SignalrHub.IntegrationEvents.Events;
2020
using RabbitMQ.Client;
2121
using System;
22+
using System.Threading.Tasks;
2223
using System.IdentityModel.Tokens.Jwt;
2324

2425
namespace Ordering.SignalrHub
@@ -109,7 +110,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
109110
RegisterEventBus(services);
110111

111112
services.AddOptions();
112-
113+
113114
//configure autofac
114115
var container = new ContainerBuilder();
115116
container.RegisterModule(new ApplicationModule());
@@ -133,7 +134,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
133134
loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase);
134135
app.UsePathBase(pathBase);
135136
}
136-
137+
137138
app.UseRouting();
138139
app.UseCors("CorsPolicy");
139140
app.UseAuthentication();
@@ -150,7 +151,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
150151
{
151152
Predicate = r => r.Name.Contains("self")
152153
});
153-
endpoints.MapHub<NotificationsHub>("/hub/notificationhub", options => options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransports.All);
154+
endpoints.MapHub<NotificationsHub>("/hub/notificationhub");
154155
});
155156

156157
ConfigureEventBus(app);
@@ -185,6 +186,20 @@ private void ConfigureAuthService(IServiceCollection services)
185186
options.Authority = identityUrl;
186187
options.RequireHttpsMetadata = false;
187188
options.Audience = "orders.signalrhub";
189+
options.Events = new JwtBearerEvents
190+
{
191+
OnMessageReceived = context =>
192+
{
193+
var accessToken = context.Request.Query["access_token"];
194+
195+
var path = context.HttpContext.Request.Path;
196+
if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/hub/notificationhub")))
197+
{
198+
context.Token = accessToken;
199+
}
200+
return Task.CompletedTask;
201+
}
202+
};
188203
});
189204
}
190205

src/Web/WebMVC/Controllers/AccountController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public AccountController(ILogger<AccountController> logger)
2020
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
2121
}
2222

23-
[Authorize(AuthenticationSchemes = "OpenIdConnect")] public async Task<IActionResult> SignIn(string returnUrl)
23+
[Authorize(AuthenticationSchemes = "OpenIdConnect")]
24+
public async Task<IActionResult> SignIn(string returnUrl)
2425
{
2526
var user = User as ClaimsPrincipal;
2627
var token = await HttpContext.GetTokenAsync("access_token");

src/Web/WebMVC/Services/LocationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public LocationService(HttpClient httpClient, IOptions<AppSettings> settings, IL
2323
_settings = settings;
2424
_logger = logger;
2525

26-
_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/api/v1/l/locations/";
26+
_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/l/api/v1/locations/";
2727
}
2828

2929
public async Task CreateOrUpdateUserLocation(LocationDTO location)

src/Web/WebMVC/libman.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"provider": "unpkg",
40-
"library": "@microsoft/signalr@3.0.1",
40+
"library": "@microsoft/signalr@latest",
4141
"destination": "wwwroot/lib/@microsoft/signalr/",
4242
"files": [
4343
"dist/browser/signalr.js",

0 commit comments

Comments
 (0)