Skip to content

Commit

Permalink
(#107) SignalR Authentication and Authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Sep 18, 2021
1 parent 03f21d3 commit b225eb9
Show file tree
Hide file tree
Showing 33 changed files with 567 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,41 @@ data:
ReRoutes__1__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-product-api"
ReRoutes__1__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__2__DownstreamScheme: "http"
ReRoutes__2__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-storage-api"
ReRoutes__2__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-product-api"
ReRoutes__2__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__3__DownstreamScheme: "http"
ReRoutes__3__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-storage-api"
ReRoutes__3__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__4__DownstreamScheme: "http"
ReRoutes__4__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-auditlog-api"
ReRoutes__4__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-storage-api"
ReRoutes__4__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__5__DownstreamScheme: "http"
ReRoutes__5__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-auditlog-api"
ReRoutes__5__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-storage-api"
ReRoutes__5__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__6__DownstreamScheme: "http"
ReRoutes__6__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-identity-api"
ReRoutes__6__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-auditlog-api"
ReRoutes__6__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__7__DownstreamScheme: "http"
ReRoutes__7__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-identity-api"
ReRoutes__7__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-auditlog-api"
ReRoutes__7__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__8__DownstreamScheme: "http"
ReRoutes__8__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-configuration-api"
ReRoutes__8__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-auditlog-api"
ReRoutes__8__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__9__DownstreamScheme: "http"
ReRoutes__9__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-configuration-api"
ReRoutes__9__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-identity-api"
ReRoutes__9__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__10__DownstreamScheme: "http"
ReRoutes__10__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-identity-api"
ReRoutes__10__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__11__DownstreamScheme: "http"
ReRoutes__11__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-identity-api"
ReRoutes__11__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__12__DownstreamScheme: "http"
ReRoutes__12__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-configuration-api"
ReRoutes__12__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__13__DownstreamScheme: "http"
ReRoutes__13__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-configuration-api"
ReRoutes__13__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__14__DownstreamScheme: "http"
ReRoutes__14__DownstreamHostAndPorts__0__Host: "{{ .Release.Name}}-configuration-api"
ReRoutes__14__DownstreamHostAndPorts__0__Port: "80"
29 changes: 22 additions & 7 deletions src/Microservices/.k8s/webapi.configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,41 @@ data:
ReRoutes__1__DownstreamHostAndPorts__0__Host: "product-api"
ReRoutes__1__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__2__DownstreamScheme: "http"
ReRoutes__2__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__2__DownstreamHostAndPorts__0__Host: "product-api"
ReRoutes__2__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__3__DownstreamScheme: "http"
ReRoutes__3__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__3__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__4__DownstreamScheme: "http"
ReRoutes__4__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__4__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__4__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__5__DownstreamScheme: "http"
ReRoutes__5__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__5__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__5__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__6__DownstreamScheme: "http"
ReRoutes__6__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__6__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__6__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__7__DownstreamScheme: "http"
ReRoutes__7__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__7__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__7__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__8__DownstreamScheme: "http"
ReRoutes__8__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__8__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__8__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__9__DownstreamScheme: "http"
ReRoutes__9__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__9__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__9__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__10__DownstreamScheme: "http"
ReRoutes__10__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__10__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__11__DownstreamScheme: "http"
ReRoutes__11__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__11__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__12__DownstreamScheme: "http"
ReRoutes__12__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__12__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__13__DownstreamScheme: "http"
ReRoutes__13__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__13__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__14__DownstreamScheme: "http"
ReRoutes__14__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__14__DownstreamHostAndPorts__0__Port: "80"
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
],
"UpstreamPathTemplate": "/api/products"
},
{
"DownstreamPathTemplate": "/api/products/",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44328
}
],
"UpstreamPathTemplate": "/api/products/"
},
{
"DownstreamPathTemplate": "/api/products/{everything}",
"DownstreamScheme": "https",
Expand All @@ -41,6 +52,17 @@
],
"UpstreamPathTemplate": "/api/files"
},
{
"DownstreamPathTemplate": "/api/files/",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44345
}
],
"UpstreamPathTemplate": "/api/files/"
},
{
"DownstreamPathTemplate": "/api/files/{everything}",
"DownstreamScheme": "https",
Expand All @@ -63,6 +85,17 @@
],
"UpstreamPathTemplate": "/api/auditLogEntries"
},
{
"DownstreamPathTemplate": "/api/auditLogEntries/",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44378
}
],
"UpstreamPathTemplate": "/api/auditLogEntries/"
},
{
"DownstreamPathTemplate": "/api/auditLogEntries/{everything}",
"DownstreamScheme": "https",
Expand All @@ -85,6 +118,17 @@
],
"UpstreamPathTemplate": "/api/users"
},
{
"DownstreamPathTemplate": "/api/users/",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44306
}
],
"UpstreamPathTemplate": "/api/users/"
},
{
"DownstreamPathTemplate": "/api/users/{everything}",
"DownstreamScheme": "https",
Expand All @@ -107,6 +151,17 @@
],
"UpstreamPathTemplate": "/api/ConfigurationEntries"
},
{
"DownstreamPathTemplate": "/api/ConfigurationEntries/",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44301
}
],
"UpstreamPathTemplate": "/api/ConfigurationEntries/"
},
{
"DownstreamPathTemplate": "/api/ConfigurationEntries/{everything}",
"DownstreamScheme": "https",
Expand Down
29 changes: 22 additions & 7 deletions src/Microservices/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,41 @@ services:
ReRoutes__1__DownstreamHostAndPorts__0__Host: "product-api"
ReRoutes__1__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__2__DownstreamScheme: "http"
ReRoutes__2__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__2__DownstreamHostAndPorts__0__Host: "product-api"
ReRoutes__2__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__3__DownstreamScheme: "http"
ReRoutes__3__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__3__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__4__DownstreamScheme: "http"
ReRoutes__4__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__4__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__4__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__5__DownstreamScheme: "http"
ReRoutes__5__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__5__DownstreamHostAndPorts__0__Host: "storage-api"
ReRoutes__5__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__6__DownstreamScheme: "http"
ReRoutes__6__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__6__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__6__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__7__DownstreamScheme: "http"
ReRoutes__7__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__7__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__7__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__8__DownstreamScheme: "http"
ReRoutes__8__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__8__DownstreamHostAndPorts__0__Host: "auditlog-api"
ReRoutes__8__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__9__DownstreamScheme: "http"
ReRoutes__9__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__9__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__9__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__10__DownstreamScheme: "http"
ReRoutes__10__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__10__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__11__DownstreamScheme: "http"
ReRoutes__11__DownstreamHostAndPorts__0__Host: "identity-api"
ReRoutes__11__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__12__DownstreamScheme: "http"
ReRoutes__12__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__12__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__13__DownstreamScheme: "http"
ReRoutes__13__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__13__DownstreamHostAndPorts__0__Port: "80"
ReRoutes__14__DownstreamScheme: "http"
ReRoutes__14__DownstreamHostAndPorts__0__Host: "configuration-api"
ReRoutes__14__DownstreamHostAndPorts__0__Port: "80"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
using ClassifiedAds.Infrastructure.Notification.Web;
using ClassifiedAds.Modules.Notification.Contracts.DTOs;
using ClassifiedAds.Modules.Notification.Hubs;
using ClassifiedAds.Modules.Notification.Services;
using ClassifiedAds.Modules.Storage.DTOs;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -145,4 +144,10 @@ private void RunMessageBrokerReceivers(IServiceProvider serviceProvider)
});
}
}

internal class SendTaskStatusMessage
{
public string Step { get; internal set; }
public string Message { get; internal set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;

namespace ClassifiedAds.Modules.Notification.Hubs
{
[Authorize]
public class NotificationHub : Hub
{
}
}

This file was deleted.

7 changes: 6 additions & 1 deletion src/ModularMonolith/ClassifiedAds.WebAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ClassifiedAds.Modules.Identity.Contracts.Services;
using ClassifiedAds.Modules.Identity.Repositories;
using ClassifiedAds.Modules.Identity.Services;
using ClassifiedAds.Modules.Notification.Hubs;
using ClassifiedAds.WebAPI.ConfigurationOptions;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -55,12 +56,15 @@ public void ConfigureServices(IServiceCollection services)
.AddStorageModule()
.AddMonitoringServices(AppSettings.Monitoring);

services.AddSignalR();

services.AddCors(options =>
{
options.AddPolicy("AllowedOrigins", builder => builder
.WithOrigins(AppSettings.CORS.AllowedOrigins)
.AllowAnyMethod()
.AllowAnyHeader());
.AllowAnyHeader()
.AllowCredentials());

options.AddPolicy("AllowAnyOrigin", builder => builder
.AllowAnyOrigin()
Expand Down Expand Up @@ -281,6 +285,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<NotificationHub>("/hubs/notification");
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/Monolith/ClassifiedAds.WebAPI/Hubs/NotificationHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;

namespace ClassifiedAds.WebAPI.Hubs
{
[Authorize]
public class NotificationHub : Hub
{
}
}
7 changes: 6 additions & 1 deletion src/Monolith/ClassifiedAds.WebAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ClassifiedAds.Infrastructure.Web.Filters;
using ClassifiedAds.Persistence;
using ClassifiedAds.WebAPI.ConfigurationOptions;
using ClassifiedAds.WebAPI.Hubs;
using ClassifiedAds.WebAPI.Tenants;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -54,12 +55,15 @@ public void ConfigureServices(IServiceCollection services)
configure.Filters.Add(typeof(GlobalExceptionFilter));
}).AddMonitoringServices(AppSettings.Monitoring);

services.AddSignalR();

services.AddCors(options =>
{
options.AddPolicy("AllowedOrigins", builder => builder
.WithOrigins(AppSettings.CORS.AllowedOrigins)
.AllowAnyMethod()
.AllowAnyHeader());
.AllowAnyHeader()
.AllowCredentials());

options.AddPolicy("AllowAnyOrigin", builder => builder
.AllowAnyOrigin()
Expand Down Expand Up @@ -245,6 +249,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<NotificationHub>("/hubs/notification");
});
}
}
Expand Down
Loading

0 comments on commit b225eb9

Please sign in to comment.