diff --git a/TIAMSharedUI/wwwroot/css/TourIAm.css b/TIAMSharedUI/wwwroot/css/TourIAm.css
index f66f8436..3878a143 100644
--- a/TIAMSharedUI/wwwroot/css/TourIAm.css
+++ b/TIAMSharedUI/wwwroot/css/TourIAm.css
@@ -395,9 +395,9 @@ select:focus-visible {
border: none;
outline: none;
background: none;
- font-size: 1.2rem;
+ /*font-size: 1.2rem;*/
color: #666;
- padding: 10px 15px 10px 10px;
+ /*padding: 10px 15px 10px 10px;*/
/* border: 1px solid red; */
}
diff --git a/TIAMWebApp/Client/App.razor b/TIAMWebApp/Client/App.razor
index 0309b495..c97a5c8b 100644
--- a/TIAMWebApp/Client/App.razor
+++ b/TIAMWebApp/Client/App.razor
@@ -1,5 +1,6 @@
-@using TIAMSharedUI.Shared
-
+@using Microsoft.AspNetCore.Components.Authorization
+@using TIAMSharedUI.Shared
+@*
@@ -10,4 +11,22 @@
Sorry, there's nothing at this address.
-
+ *@
+
+
+
+
+
+ Sorry dude, but you're not authorized!
+
+
+
+
+
+ Not found
+
+ Sorry, there's nothing at this address.
+
+
+
+
diff --git a/TIAMWebApp/Client/Program.cs b/TIAMWebApp/Client/Program.cs
index d04a513f..fcafaf9c 100644
--- a/TIAMWebApp/Client/Program.cs
+++ b/TIAMWebApp/Client/Program.cs
@@ -4,7 +4,7 @@ using Blazored.LocalStorage;
using DevExpress.Blazor;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
-using Microsoft.JSInterop;
+using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using System.Reflection;
using System.Resources;
using AyCode.Core.Loggers;
@@ -15,6 +15,8 @@ using TIAMWebApp.Shared.Application.Services;
using TIAMWebApp.Shared.Application.Utility;
using AyCode.Services.Loggers;
using System.Net;
+using Microsoft.AspNetCore.Components.Authorization;
+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
@@ -45,7 +47,8 @@ builder.Services.AddSingleton
//builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddSingleton();
-
+builder.Services.AddScoped();
+builder.Services.AddAuthorizationCore();
//builder.Services.AddScoped();
//WebSpecific end
diff --git a/TIAMWebApp/Client/TIAMWebApp.Client.csproj b/TIAMWebApp/Client/TIAMWebApp.Client.csproj
index af06138e..cd9fc6a6 100644
--- a/TIAMWebApp/Client/TIAMWebApp.Client.csproj
+++ b/TIAMWebApp/Client/TIAMWebApp.Client.csproj
@@ -12,6 +12,7 @@
+
diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs
index 946531ee..1595fef0 100644
--- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs
+++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs
@@ -15,6 +15,7 @@ using TIAM.Services.Server;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide.Messages;
using TIAMWebApp.Shared.Application.Services;
+using TIAMWebApp.Server.Services;
namespace TIAMWebApp.Server.Controllers
{
@@ -39,14 +40,16 @@ namespace TIAMWebApp.Server.Controllers
private readonly TIAM.Core.Loggers.ILogger _logger;
private readonly TransferBackendService _transferBackendService;
private readonly IMessageSenderService _messageSenderService;
+ private readonly AuthService _authService;
- public TransferDataAPIController(AdminDal adminDal, TransferBackendService transferBackendService, IMessageSenderService messageSenderService, IEnumerable logWriters)
+ public TransferDataAPIController(AdminDal adminDal, TransferBackendService transferBackendService, IMessageSenderService messageSenderService, IEnumerable logWriters, AuthService authService)
{
_adminDal = adminDal;
_transferBackendService = transferBackendService;
_logger = new TIAM.Core.Loggers.Logger(logWriters.ToArray());
_messageSenderService = messageSenderService;
+ _authService = authService;
}
@@ -371,16 +374,30 @@ namespace TIAMWebApp.Server.Controllers
}
}
- [AllowAnonymous]
+ [Authorize]
[HttpGet]
[Route(APIUrls.GetTransfersRouteName)]
public async Task GetTransfers()
{
+ var token = _authService.GetAuthTokenFromRequest(Request);
+ _logger.Detail(token);
var result = await _adminDal.GetTransfersJsonAsync();
return result;
}
+ [AllowAnonymous]
+ [HttpPost]
+ [Route(APIUrls.GetTransferByIdRouteName)]
+ public async Task GetTransferById([FromBody] Guid transferID)
+ {
+ _logger.Info(@"Get transfer by id called");
+ _logger.Info($"transferId: {transferID.ToString()}");
+ var result = _adminDal.GetTransferById(transferID);
+
+ //TODO: Implementálni a Logout-ot kliens és szerver oldalon is! - J.
+ return Ok(result);
+ }
[AllowAnonymous]
[HttpPost]
diff --git a/TIAMWebApp/Server/Program.cs b/TIAMWebApp/Server/Program.cs
index 291fcb28..87d47031 100644
--- a/TIAMWebApp/Server/Program.cs
+++ b/TIAMWebApp/Server/Program.cs
@@ -41,6 +41,7 @@ builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddSingleton();
builder.Services.AddSignalR().AddMessagePackProtocol(options => options.SerializerOptions = MessagePackSerializerOptions.Standard.WithSecurity(MessagePackSecurity.UntrustedData));
@@ -179,6 +180,7 @@ app.MapBlazorHub();
app.MapHub("/TiamChatHub");
app.MapHub("/TiamLoggerHub");
//app.MapHub("/DevAdminHub");
+app.MapHub("/gamehub");
app.MapFallbackToFile("index.html");
diff --git a/TIAMWebApp/Server/Services/AuthService.cs b/TIAMWebApp/Server/Services/AuthService.cs
new file mode 100644
index 00000000..7f3a1691
--- /dev/null
+++ b/TIAMWebApp/Server/Services/AuthService.cs
@@ -0,0 +1,26 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Authorization;
+
+namespace TIAMWebApp.Server.Services
+{
+ public class AuthService
+ {
+ public string GetAuthTokenFromRequest(HttpRequest request)
+ {
+ // Check if the Authorization header is present
+ if (request.Headers.ContainsKey("Authorization"))
+ {
+ // Extract the token from the Authorization header
+ var authHeader = request.Headers["Authorization"].ToString();
+ if (authHeader.StartsWith("Bearer ", System.StringComparison.OrdinalIgnoreCase))
+ {
+ return authHeader.Substring("Bearer ".Length).Trim();
+ }
+ }
+
+ return null;
+ }
+
+ }
+}
diff --git a/TIAMWebApp/Server/Services/GameHub.cs b/TIAMWebApp/Server/Services/GameHub.cs
new file mode 100644
index 00000000..938c25fd
--- /dev/null
+++ b/TIAMWebApp/Server/Services/GameHub.cs
@@ -0,0 +1,37 @@
+using AyCode.Core.Loggers;
+using Microsoft.AspNetCore.SignalR;
+using System.Net.Http;
+using TIAM.Core.Loggers;
+
+namespace TIAMWebApp.Server.Services;
+public class GameHub : Hub
+{
+
+ private readonly TIAM.Core.Loggers.ILogger _logger;
+ public GameHub(IEnumerable logWriters)
+ {
+
+ _logger = new TIAM.Core.Loggers.Logger(logWriters.ToArray());
+ }
+
+ public async Task MakeMove(string groupName, int row, int col, string player)
+ {
+ _logger.Detail($"{groupName}, {row}, {col}, {player}");
+ await Clients.Group(groupName).SendAsync("ReceiveMove", row, col, player);
+ }
+
+ public async Task JoinGame(string groupName)
+ {
+ _logger.Detail(groupName);
+ await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
+ await Clients.Group(groupName).SendAsync("PlayerJoined", Context.ConnectionId);
+ }
+
+
+ public async Task LeaveGame(string groupName)
+ {
+ await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
+ await Clients.Group(groupName).SendAsync("PlayerLeft", Context.ConnectionId);
+ }
+}
+
diff --git a/TIAMWebApp/Shared/Services/CustomAuthStateProvider.cs b/TIAMWebApp/Shared/Services/CustomAuthStateProvider.cs
new file mode 100644
index 00000000..8fa8fb83
--- /dev/null
+++ b/TIAMWebApp/Shared/Services/CustomAuthStateProvider.cs
@@ -0,0 +1,78 @@
+using AyCode.Interfaces.StorageHandlers;
+using Microsoft.AspNetCore.Components.Authorization;
+using Newtonsoft.Json;
+using System.IdentityModel.Tokens.Jwt;
+using System.Net.Http.Headers;
+using System.Security.Claims;
+using System.Text.Json;
+using TIAMWebApp.Shared.Application.Models.ClientSide;
+
+namespace TIAMWebApp.Shared.Application.Services
+{
+ public class CustomAuthStateProvider : AuthenticationStateProvider
+ {
+ private readonly ISecureStorageHandler _localStorage;
+ private readonly HttpClient _http;
+
+
+
+ public CustomAuthStateProvider(ISecureStorageHandler localStorage, HttpClient http)
+ {
+ _localStorage = localStorage;
+ _http = http;
+ }
+
+ public override async Task GetAuthenticationStateAsync()
+ {
+ string userDetailsStr = await _localStorage.GetFromSecureStorageAsync(nameof(Setting.UserBasicDetails));
+ AuthenticationState state = null;
+ if (!string.IsNullOrEmpty(userDetailsStr))
+ {
+
+ var userBasicDetail = JsonConvert.DeserializeObject(userDetailsStr);
+
+ //var handler = new JwtSecurityTokenHandler();
+ //var jsontoken = handler.ReadToken(userBasicDetail?.AccessToken) as JwtSecurityToken;
+ var token = userBasicDetail?.AccessToken;
+ var identity = new ClaimsIdentity();
+ _http.DefaultRequestHeaders.Authorization = null;
+
+ if (!string.IsNullOrEmpty(token))
+ {
+ identity = new ClaimsIdentity(ParseClaimsFromJwt(token), "jwt");
+ _http.DefaultRequestHeaders.Authorization =
+ new AuthenticationHeaderValue("Bearer", token.Replace("\"", ""));
+ }
+
+ var user = new ClaimsPrincipal(identity);
+ state = new AuthenticationState(user);
+
+ NotifyAuthenticationStateChanged(Task.FromResult(state));
+ }
+ else
+ {
+ state = new AuthenticationState(new ClaimsPrincipal());
+ }
+
+ return state;
+ }
+
+ public static IEnumerable ParseClaimsFromJwt(string jwt)
+ {
+ var payload = jwt.Split('.')[1];
+ var jsonBytes = ParseBase64WithoutPadding(payload);
+ var keyValuePairs = System.Text.Json.JsonSerializer.Deserialize>(jsonBytes);
+ return keyValuePairs.Select(kvp => new Claim(kvp.Key, kvp.Value.ToString()));
+ }
+
+ private static byte[] ParseBase64WithoutPadding(string base64)
+ {
+ switch (base64.Length % 4)
+ {
+ case 2: base64 += "=="; break;
+ case 3: base64 += "="; break;
+ }
+ return Convert.FromBase64String(base64);
+ }
+ }
+}
\ No newline at end of file
diff --git a/TIAMWebApp/Shared/Services/TransferDataService.cs b/TIAMWebApp/Shared/Services/TransferDataService.cs
index b035480c..da98b4d7 100644
--- a/TIAMWebApp/Shared/Services/TransferDataService.cs
+++ b/TIAMWebApp/Shared/Services/TransferDataService.cs
@@ -152,13 +152,18 @@ namespace TIAMWebApp.Shared.Application.Services
public async Task GetTransferByIdAsync(Guid id)
{
+ Transfer resultTransfer;
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetTransferById}";
//var url = $"{APIUrls.GetTransferDestinations}";
_logger.Info(url);
- Transfer? response = await _http.GetFromJsonAsync(url);
+ var response = await _http.PostAsJsonAsync(url, id);
if (response == null)
return new Transfer();
- return response;
+ else
+ {
+ resultTransfer = (Transfer)(await response.Content.ReadFromJsonAsync(typeof(Transfer)));
+ }
+ return resultTransfer;
}
public async Task> GetTransfersAsync()
diff --git a/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj b/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj
index e48df739..22df6d05 100644
--- a/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj
+++ b/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj
@@ -22,6 +22,7 @@
+