This commit is contained in:
2021-08-01 17:32:43 -05:00
parent 178cb00253
commit b10f61a489
76 changed files with 1655 additions and 1185 deletions

View File

@@ -3,7 +3,7 @@ using Gameboard.ShogiUI.Sockets.Extensions;
using Gameboard.ShogiUI.Sockets.Managers;
using Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket;
using Gameboard.ShogiUI.Sockets.Services;
using Gameboard.ShogiUI.Sockets.Services.RequestValidators;
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -18,6 +18,7 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gameboard.ShogiUI.Sockets
{
@@ -45,7 +46,6 @@ namespace Gameboard.ShogiUI.Sockets
services.AddSingleton<ISocketConnectionManager, SocketConnectionManager>();
services.AddSingleton<ISocketTokenManager, SocketTokenManager>();
services.AddSingleton<IGameboardManager, GameboardManager>();
services.AddSingleton<IActiveSessionManager, ActiveSessionManager>();
// Services
services.AddSingleton<IValidator<CreateGameRequest>, CreateGameRequestValidator>();
@@ -84,6 +84,18 @@ namespace Gameboard.ShogiUI.Sockets
options.Audience = "935df672-efa6-45fa-b2e8-b76dfd65a122";
options.TokenValidationParameters.ValidateIssuer = true;
options.TokenValidationParameters.ValidateAudience = true;
options.Events = new JwtBearerEvents
{
OnMessageReceived = (context) =>
{
if (context.HttpContext.WebSockets.IsWebSocketRequest)
{
Console.WriteLine("Yep");
}
return Task.FromResult(0);
}
};
});
}
@@ -114,6 +126,7 @@ namespace Gameboard.ShogiUI.Sockets
.WithOrigins(origins)
.AllowAnyMethod()
.AllowAnyHeader()
.WithExposedHeaders("Set-Cookie")
.AllowCredentials()
)
.UseRouting()
@@ -126,12 +139,7 @@ namespace Gameboard.ShogiUI.Sockets
})
.Use(async (context, next) =>
{
var isUpgradeHeader = context
.Request
.Headers
.Any(h => h.Key.Contains("upgrade", StringComparison.InvariantCultureIgnoreCase)
&& h.Value.ToString().Contains("websocket", StringComparison.InvariantCultureIgnoreCase));
if (isUpgradeHeader)
if (context.WebSockets.IsWebSocketRequest)
{
await socketConnectionManager.HandleSocketRequest(context);
}