diff --git a/sources/Clients.Admin/Application/Authentications/GrpcHttpMessageHandler.cs b/sources/Clients.Admin/Application/Authentications/GrpcHttpMessageHandler.cs deleted file mode 100644 index 029b1c1..0000000 --- a/sources/Clients.Admin/Application/Authentications/GrpcHttpMessageHandler.cs +++ /dev/null @@ -1,50 +0,0 @@ -using MadWorldNL.Clients.Admin.Domain.Authentications; - -namespace MadWorldNL.Clients.Admin.Application.Authentications; - -public class GrpcHttpMessageHandler : DelegatingHandler -{ - private readonly IAuthenticationManager _authenticationManager; - - public GrpcHttpMessageHandler(IAuthenticationManager authenticationManager) - { - _authenticationManager = authenticationManager; - } - - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - var token = await GetJwtTokenAsync(); - request.Headers.Add("Authorization", $"Bearer {token}"); - - return await base.SendAsync(request, cancellationToken); - } - - protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken) - { - return SendAsync(request, cancellationToken).GetAwaiter().GetResult(); - } - - private async Task GetJwtTokenAsync() - { - var authenticationToken = await _authenticationManager.GetCurrentAuthenticationTokenAsync(); - - if (!authenticationToken.IsSuccess) - { - throw new AuthenticationTokenException(); - } - - if (authenticationToken.Expires >= DateTime.UtcNow.AddMinutes(5)) - { - return authenticationToken.AccessToken; - } - - authenticationToken = await _authenticationManager.RefreshTokenAsync(); - - if (!authenticationToken.IsSuccess) - { - throw new AuthenticationTokenException(); - } - - return authenticationToken.AccessToken; - } -} \ No newline at end of file diff --git a/sources/Clients.Admin/Application/Authentications/AuthenticationManager.cs b/sources/Clients.Admin_Old/Application/Authentications/AuthenticationManager.cs similarity index 94% rename from sources/Clients.Admin/Application/Authentications/AuthenticationManager.cs rename to sources/Clients.Admin_Old/Application/Authentications/AuthenticationManager.cs index e02d984..377e36c 100644 --- a/sources/Clients.Admin/Application/Authentications/AuthenticationManager.cs +++ b/sources/Clients.Admin_Old/Application/Authentications/AuthenticationManager.cs @@ -39,7 +39,7 @@ public async Task LoginFromSessionAsync() if (token.IsSuccess) { - _authenticationStateProvider.Authenticate(token.AccessToken); + _authenticationStateProvider.Authenticate(token); } return token; @@ -88,6 +88,6 @@ public async Task RefreshTokenAsync() private async Task AuthenticateAsync(AuthenticationToken token) { await _localStorage.SetAsync(AuthenticationToken.Entry, token); - _authenticationStateProvider.Authenticate(token.AccessToken); + _authenticationStateProvider.Authenticate(token); } } \ No newline at end of file diff --git a/sources/Clients.Admin_Old/Application/Authentications/GrpcHttpMessageHandler.cs b/sources/Clients.Admin_Old/Application/Authentications/GrpcHttpMessageHandler.cs new file mode 100644 index 0000000..149dd44 --- /dev/null +++ b/sources/Clients.Admin_Old/Application/Authentications/GrpcHttpMessageHandler.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Components.Authorization; + +namespace MadWorldNL.Clients.Admin.Application.Authentications; + +public class GrpcHttpMessageHandler : DelegatingHandler +{ + private readonly UserService _userService; + private readonly JwtAuthenticationStateProvider _authenticationStateProvider; + + public GrpcHttpMessageHandler(AuthenticationStateProvider authenticationStateProvider, UserService userService) + { + _userService = userService; + _authenticationStateProvider = (JwtAuthenticationStateProvider)authenticationStateProvider; + } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + var test = _userService.GetUser(); + + var token = _authenticationStateProvider.GetCurrentToken().AccessToken; + request.Headers.Add("Authorization", $"Bearer {token}"); + + return await base.SendAsync(request, cancellationToken); + } + + protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken) + { + return SendAsync(request, cancellationToken).GetAwaiter().GetResult(); + } +} \ No newline at end of file diff --git a/sources/Clients.Admin/Application/Authentications/IAuthenticationManager.cs b/sources/Clients.Admin_Old/Application/Authentications/IAuthenticationManager.cs similarity index 100% rename from sources/Clients.Admin/Application/Authentications/IAuthenticationManager.cs rename to sources/Clients.Admin_Old/Application/Authentications/IAuthenticationManager.cs diff --git a/sources/Clients.Admin/Application/Authentications/JwtAuthenticationStateProvider.cs b/sources/Clients.Admin_Old/Application/Authentications/JwtAuthenticationStateProvider.cs similarity index 72% rename from sources/Clients.Admin/Application/Authentications/JwtAuthenticationStateProvider.cs rename to sources/Clients.Admin_Old/Application/Authentications/JwtAuthenticationStateProvider.cs index e4dd020..712dffc 100644 --- a/sources/Clients.Admin/Application/Authentications/JwtAuthenticationStateProvider.cs +++ b/sources/Clients.Admin_Old/Application/Authentications/JwtAuthenticationStateProvider.cs @@ -1,5 +1,6 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; +using MadWorldNL.Clients.Admin.Domain.Authentications; using Microsoft.AspNetCore.Components.Authorization; namespace MadWorldNL.Clients.Admin.Application.Authentications; @@ -8,16 +9,24 @@ public class JwtAuthenticationStateProvider : AuthenticationStateProvider { private const string AuthenticationType = "jwt"; + private AuthenticationToken _currentToken = new(); private AuthenticationState _currentUserState = GetAnonymous(); public override Task GetAuthenticationStateAsync() { return Task.FromResult(_currentUserState); } + + public AuthenticationToken GetCurrentToken() + { + return _currentToken; + } - public void Authenticate(string jwtToken) + public void Authenticate(AuthenticationToken token) { - var securityToken = new JwtSecurityToken(jwtToken); + _currentToken = token; + + var securityToken = new JwtSecurityToken(token.AccessToken); var identity = new ClaimsIdentity(securityToken.Claims, AuthenticationType, "name", "role"); var user = new ClaimsPrincipal(identity); _currentUserState = new AuthenticationState(user); @@ -26,6 +35,8 @@ public void Authenticate(string jwtToken) public void Logout() { + _currentToken = new AuthenticationToken(); + _currentUserState = GetAnonymous(); NotifyAuthenticationStateChanged(Task.FromResult(_currentUserState)); } diff --git a/sources/Clients.Admin_Old/Application/Authentications/UserService.cs b/sources/Clients.Admin_Old/Application/Authentications/UserService.cs new file mode 100644 index 0000000..e5fee45 --- /dev/null +++ b/sources/Clients.Admin_Old/Application/Authentications/UserService.cs @@ -0,0 +1,76 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Server.Circuits; + +namespace MadWorldNL.Clients.Admin.Application.Authentications; + +public class UserService +{ + private ClaimsPrincipal currentUser = new(new ClaimsIdentity()); + + public ClaimsPrincipal GetUser() + { + return currentUser; + } + + internal void SetUser(ClaimsPrincipal user) + { + if (currentUser != user) + { + currentUser = user; + } + } +} + +internal sealed class UserCircuitHandler : CircuitHandler, IDisposable +{ + private readonly AuthenticationStateProvider authenticationStateProvider; + private readonly UserService userService; + + public UserCircuitHandler( + AuthenticationStateProvider authenticationStateProvider, + UserService userService) + { + this.authenticationStateProvider = authenticationStateProvider; + this.userService = userService; + } + + public override Task OnCircuitOpenedAsync(Circuit circuit, + CancellationToken cancellationToken) + { + authenticationStateProvider.AuthenticationStateChanged += + AuthenticationChanged; + + return base.OnCircuitOpenedAsync(circuit, cancellationToken); + } + + private void AuthenticationChanged(Task task) + { + _ = UpdateAuthentication(task); + + async Task UpdateAuthentication(Task task) + { + try + { + var state = await task; + userService.SetUser(state.User); + } + catch + { + } + } + } + + public override async Task OnConnectionUpAsync(Circuit circuit, + CancellationToken cancellationToken) + { + var state = await authenticationStateProvider.GetAuthenticationStateAsync(); + userService.SetUser(state.User); + } + + public void Dispose() + { + authenticationStateProvider.AuthenticationStateChanged -= + AuthenticationChanged; + } +} diff --git a/sources/Clients.Admin_Old/Application/Authentications/UserServiceMiddleware.cs b/sources/Clients.Admin_Old/Application/Authentications/UserServiceMiddleware.cs new file mode 100644 index 0000000..9fedd14 --- /dev/null +++ b/sources/Clients.Admin_Old/Application/Authentications/UserServiceMiddleware.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Components.Authorization; + +namespace MadWorldNL.Clients.Admin.Application.Authentications; + +public class UserServiceMiddleware +{ + private readonly RequestDelegate next; + + public UserServiceMiddleware(RequestDelegate next) + { + this.next = next ?? throw new ArgumentNullException(nameof(next)); + } + + public async Task InvokeAsync(HttpContext context, UserService service, AuthenticationStateProvider provider) + { + service.SetUser(context.User); + await next(context); + } +} \ No newline at end of file diff --git a/sources/Clients.Admin/Clients.Admin.csproj b/sources/Clients.Admin_Old/Clients.Admin_Old.csproj similarity index 100% rename from sources/Clients.Admin/Clients.Admin.csproj rename to sources/Clients.Admin_Old/Clients.Admin_Old.csproj diff --git a/sources/Clients.Admin/Components/App.razor b/sources/Clients.Admin_Old/Components/App.razor similarity index 100% rename from sources/Clients.Admin/Components/App.razor rename to sources/Clients.Admin_Old/Components/App.razor diff --git a/sources/Clients.Admin/Components/Layout/MainLayout.razor b/sources/Clients.Admin_Old/Components/Layout/MainLayout.razor similarity index 100% rename from sources/Clients.Admin/Components/Layout/MainLayout.razor rename to sources/Clients.Admin_Old/Components/Layout/MainLayout.razor diff --git a/sources/Clients.Admin/Components/Layout/MainLayout.razor.css b/sources/Clients.Admin_Old/Components/Layout/MainLayout.razor.css similarity index 100% rename from sources/Clients.Admin/Components/Layout/MainLayout.razor.css rename to sources/Clients.Admin_Old/Components/Layout/MainLayout.razor.css diff --git a/sources/Clients.Admin/Components/Layout/NavMenu.razor b/sources/Clients.Admin_Old/Components/Layout/NavMenu.razor similarity index 95% rename from sources/Clients.Admin/Components/Layout/NavMenu.razor rename to sources/Clients.Admin_Old/Components/Layout/NavMenu.razor index b461322..3790293 100644 --- a/sources/Clients.Admin/Components/Layout/NavMenu.razor +++ b/sources/Clients.Admin_Old/Components/Layout/NavMenu.razor @@ -1,6 +1,6 @@  diff --git a/sources/Clients.Admin/Components/Layout/NavMenu.razor.css b/sources/Clients.Admin_Old/Components/Layout/NavMenu.razor.css similarity index 100% rename from sources/Clients.Admin/Components/Layout/NavMenu.razor.css rename to sources/Clients.Admin_Old/Components/Layout/NavMenu.razor.css diff --git a/sources/Clients.Admin/Components/Pages/Authentications/AuthenticationTest.razor b/sources/Clients.Admin_Old/Components/Pages/Authentications/AuthenticationTest.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Authentications/AuthenticationTest.razor rename to sources/Clients.Admin_Old/Components/Pages/Authentications/AuthenticationTest.razor diff --git a/sources/Clients.Admin/Components/Pages/Authentications/Login.razor b/sources/Clients.Admin_Old/Components/Pages/Authentications/Login.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Authentications/Login.razor rename to sources/Clients.Admin_Old/Components/Pages/Authentications/Login.razor diff --git a/sources/Clients.Admin/Components/Pages/Authentications/Logout.razor b/sources/Clients.Admin_Old/Components/Pages/Authentications/Logout.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Authentications/Logout.razor rename to sources/Clients.Admin_Old/Components/Pages/Authentications/Logout.razor diff --git a/sources/Clients.Admin/Components/Pages/Authentications/RedirectToLogin.razor b/sources/Clients.Admin_Old/Components/Pages/Authentications/RedirectToLogin.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Authentications/RedirectToLogin.razor rename to sources/Clients.Admin_Old/Components/Pages/Authentications/RedirectToLogin.razor diff --git a/sources/Clients.Admin/Components/Pages/Counter.razor b/sources/Clients.Admin_Old/Components/Pages/Counter.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Counter.razor rename to sources/Clients.Admin_Old/Components/Pages/Counter.razor diff --git a/sources/Clients.Admin/Components/Pages/Error.razor b/sources/Clients.Admin_Old/Components/Pages/Error.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Error.razor rename to sources/Clients.Admin_Old/Components/Pages/Error.razor diff --git a/sources/Clients.Admin/Components/Pages/Home.razor b/sources/Clients.Admin_Old/Components/Pages/Home.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Home.razor rename to sources/Clients.Admin_Old/Components/Pages/Home.razor diff --git a/sources/Clients.Admin/Components/Pages/UserManagers/Users.razor b/sources/Clients.Admin_Old/Components/Pages/UserManagers/Users.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/UserManagers/Users.razor rename to sources/Clients.Admin_Old/Components/Pages/UserManagers/Users.razor diff --git a/sources/Clients.Admin/Components/Pages/Weather.razor b/sources/Clients.Admin_Old/Components/Pages/Weather.razor similarity index 100% rename from sources/Clients.Admin/Components/Pages/Weather.razor rename to sources/Clients.Admin_Old/Components/Pages/Weather.razor diff --git a/sources/Clients.Admin/Components/Routes.razor b/sources/Clients.Admin_Old/Components/Routes.razor similarity index 100% rename from sources/Clients.Admin/Components/Routes.razor rename to sources/Clients.Admin_Old/Components/Routes.razor diff --git a/sources/Clients.Admin/Components/_Imports.razor b/sources/Clients.Admin_Old/Components/_Imports.razor similarity index 100% rename from sources/Clients.Admin/Components/_Imports.razor rename to sources/Clients.Admin_Old/Components/_Imports.razor diff --git a/sources/Clients.Admin/Dockerfile b/sources/Clients.Admin_Old/Dockerfile similarity index 100% rename from sources/Clients.Admin/Dockerfile rename to sources/Clients.Admin_Old/Dockerfile diff --git a/sources/Clients.Admin/Domain/Authentications/AuthenticationToken.cs b/sources/Clients.Admin_Old/Domain/Authentications/AuthenticationToken.cs similarity index 100% rename from sources/Clients.Admin/Domain/Authentications/AuthenticationToken.cs rename to sources/Clients.Admin_Old/Domain/Authentications/AuthenticationToken.cs diff --git a/sources/Clients.Admin/Domain/Authentications/AuthenticationTokenException.cs b/sources/Clients.Admin_Old/Domain/Authentications/AuthenticationTokenException.cs similarity index 100% rename from sources/Clients.Admin/Domain/Authentications/AuthenticationTokenException.cs rename to sources/Clients.Admin_Old/Domain/Authentications/AuthenticationTokenException.cs diff --git a/sources/Clients.Admin/Domain/Authorizations/Policies.cs b/sources/Clients.Admin_Old/Domain/Authorizations/Policies.cs similarity index 100% rename from sources/Clients.Admin/Domain/Authorizations/Policies.cs rename to sources/Clients.Admin_Old/Domain/Authorizations/Policies.cs diff --git a/sources/Clients.Admin/Domain/Authorizations/Roles.cs b/sources/Clients.Admin_Old/Domain/Authorizations/Roles.cs similarity index 100% rename from sources/Clients.Admin/Domain/Authorizations/Roles.cs rename to sources/Clients.Admin_Old/Domain/Authorizations/Roles.cs diff --git a/sources/Clients.Admin/Extensions/WebApplicationBuilderExtensions.cs b/sources/Clients.Admin_Old/Extensions/WebApplicationBuilderExtensions.cs similarity index 92% rename from sources/Clients.Admin/Extensions/WebApplicationBuilderExtensions.cs rename to sources/Clients.Admin_Old/Extensions/WebApplicationBuilderExtensions.cs index 5aeedab..7d17383 100644 --- a/sources/Clients.Admin/Extensions/WebApplicationBuilderExtensions.cs +++ b/sources/Clients.Admin_Old/Extensions/WebApplicationBuilderExtensions.cs @@ -1,7 +1,6 @@ using MadWorldNL.Clients.Admin.Application.Authentications; using MadWorldNL.Clients.Admin.Services.Authentications; using Microsoft.AspNetCore.Components.Authorization; -using Server.Presentation.Grpc.Account.V1; using Server.Presentation.Grpc.Authentication.V1; using Server.Presentation.Grpc.UserManager.V1; @@ -11,7 +10,7 @@ public static class WebApplicationBuilderExtensions { public static void AddGrpcClients(this WebApplicationBuilder builder) { - builder.Services.AddScoped(); + builder.Services.AddTransient(); builder.Services.AddGrpcClient(o => { diff --git a/sources/Clients.Admin/Program.cs b/sources/Clients.Admin_Old/Program.cs similarity index 84% rename from sources/Clients.Admin/Program.cs rename to sources/Clients.Admin_Old/Program.cs index 3e6ca1e..77ae03c 100644 --- a/sources/Clients.Admin/Program.cs +++ b/sources/Clients.Admin_Old/Program.cs @@ -1,8 +1,11 @@ using System.Text; +using MadWorldNL.Clients.Admin.Application.Authentications; using MadWorldNL.Clients.Admin.Components; using MadWorldNL.Clients.Admin.Domain.Authorizations; using MadWorldNL.Clients.Admin.Extensions; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Components.Server.Circuits; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.IdentityModel.Tokens; using Radzen; @@ -39,6 +42,10 @@ builder.AddGrpcClients(); builder.AddAdminServices(); +builder.Services.AddScoped(); +builder.Services.TryAddEnumerable( + ServiceDescriptor.Scoped()); + builder.Services.AddRadzenComponents(); var app = builder.Build(); @@ -62,4 +69,6 @@ app.MapRazorComponents() .AddInteractiveServerRenderMode(); +app.UseMiddleware(); + app.Run(); \ No newline at end of file diff --git a/sources/Clients.Admin/Properties/launchSettings.json b/sources/Clients.Admin_Old/Properties/launchSettings.json similarity index 100% rename from sources/Clients.Admin/Properties/launchSettings.json rename to sources/Clients.Admin_Old/Properties/launchSettings.json diff --git a/sources/Clients.Admin/Services/Authentications/AuthenticationService.cs b/sources/Clients.Admin_Old/Services/Authentications/AuthenticationService.cs similarity index 100% rename from sources/Clients.Admin/Services/Authentications/AuthenticationService.cs rename to sources/Clients.Admin_Old/Services/Authentications/AuthenticationService.cs diff --git a/sources/Clients.Admin/Services/Authentications/IAuthenticationService.cs b/sources/Clients.Admin_Old/Services/Authentications/IAuthenticationService.cs similarity index 100% rename from sources/Clients.Admin/Services/Authentications/IAuthenticationService.cs rename to sources/Clients.Admin_Old/Services/Authentications/IAuthenticationService.cs diff --git a/sources/Clients.Admin/Services/Authentications/IUserManagerService.cs b/sources/Clients.Admin_Old/Services/Authentications/IUserManagerService.cs similarity index 100% rename from sources/Clients.Admin/Services/Authentications/IUserManagerService.cs rename to sources/Clients.Admin_Old/Services/Authentications/IUserManagerService.cs diff --git a/sources/Clients.Admin/Services/Authentications/UserManagerService.cs b/sources/Clients.Admin_Old/Services/Authentications/UserManagerService.cs similarity index 100% rename from sources/Clients.Admin/Services/Authentications/UserManagerService.cs rename to sources/Clients.Admin_Old/Services/Authentications/UserManagerService.cs diff --git a/sources/Clients.Admin/appsettings.Development.json b/sources/Clients.Admin_Old/appsettings.Development.json similarity index 100% rename from sources/Clients.Admin/appsettings.Development.json rename to sources/Clients.Admin_Old/appsettings.Development.json diff --git a/sources/Clients.Admin/appsettings.json b/sources/Clients.Admin_Old/appsettings.json similarity index 100% rename from sources/Clients.Admin/appsettings.json rename to sources/Clients.Admin_Old/appsettings.json diff --git a/sources/Clients.Admin/wwwroot/app.css b/sources/Clients.Admin_Old/wwwroot/app.css similarity index 100% rename from sources/Clients.Admin/wwwroot/app.css rename to sources/Clients.Admin_Old/wwwroot/app.css diff --git a/sources/Clients.Admin/wwwroot/bootstrap/bootstrap.min.css b/sources/Clients.Admin_Old/wwwroot/bootstrap/bootstrap.min.css similarity index 100% rename from sources/Clients.Admin/wwwroot/bootstrap/bootstrap.min.css rename to sources/Clients.Admin_Old/wwwroot/bootstrap/bootstrap.min.css diff --git a/sources/Clients.Admin/wwwroot/bootstrap/bootstrap.min.css.map b/sources/Clients.Admin_Old/wwwroot/bootstrap/bootstrap.min.css.map similarity index 100% rename from sources/Clients.Admin/wwwroot/bootstrap/bootstrap.min.css.map rename to sources/Clients.Admin_Old/wwwroot/bootstrap/bootstrap.min.css.map diff --git a/sources/Clients.Admin/wwwroot/favicon.png b/sources/Clients.Admin_Old/wwwroot/favicon.png similarity index 100% rename from sources/Clients.Admin/wwwroot/favicon.png rename to sources/Clients.Admin_Old/wwwroot/favicon.png diff --git a/sources/MadWorldNL.Identity.sln b/sources/MadWorldNL.Identity.sln index b12204f..14a8e63 100644 --- a/sources/MadWorldNL.Identity.sln +++ b/sources/MadWorldNL.Identity.sln @@ -29,8 +29,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Application", "Serve EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Domain", "Server.Domain\Server.Domain.csproj", "{B8E44E4A-BA6D-43EE-BE23-23BC557BD32A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Admin", "Clients.Admin\Clients.Admin.csproj", "{DC343525-26E7-417E-9140-5DB722D44A62}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Presentation.Grpc.IntegrationTests", "Server.Presentation.Grpc.IntegrationTests\Server.Presentation.Grpc.IntegrationTests.csproj", "{60C2824A-17C1-4019-8749-65AE0448E5B3}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{6612E52A-5F38-4585-8F9C-F0F027020BBD}" @@ -42,6 +40,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSdk.Grpc", "ClientSdk.Grpc\ClientSdk.Grpc.csproj", "{9963EC55-AADF-4940-AE11-EBCD9F372920}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Admin_Old", "Clients.Admin_Old\Clients.Admin_Old.csproj", "{18DCD2E1-CF25-4FAA-816A-3CFB316DD39F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -56,10 +56,10 @@ Global {BC765338-FF40-4D9E-AC54-789E184B36F4} = {32514DC3-93DB-40F0-81CA-7525115445CA} {EA259647-3CF2-42B4-9BD3-76D0E4262383} = {32514DC3-93DB-40F0-81CA-7525115445CA} {B8E44E4A-BA6D-43EE-BE23-23BC557BD32A} = {32514DC3-93DB-40F0-81CA-7525115445CA} - {DC343525-26E7-417E-9140-5DB722D44A62} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1} {60C2824A-17C1-4019-8749-65AE0448E5B3} = {0336D5D8-8B04-4701-804F-158356ED9475} {6612E52A-5F38-4585-8F9C-F0F027020BBD} = {1648BD75-33AE-4918-AD6A-D12B0A3BC52F} {9963EC55-AADF-4940-AE11-EBCD9F372920} = {4FEA52A1-D597-4D02-A23B-15E6E41589DF} + {18DCD2E1-CF25-4FAA-816A-3CFB316DD39F} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {2B04007E-B2D9-4E8B-82D2-C553CD5F3DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -78,10 +78,6 @@ Global {B8E44E4A-BA6D-43EE-BE23-23BC557BD32A}.Debug|Any CPU.Build.0 = Debug|Any CPU {B8E44E4A-BA6D-43EE-BE23-23BC557BD32A}.Release|Any CPU.ActiveCfg = Release|Any CPU {B8E44E4A-BA6D-43EE-BE23-23BC557BD32A}.Release|Any CPU.Build.0 = Release|Any CPU - {DC343525-26E7-417E-9140-5DB722D44A62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DC343525-26E7-417E-9140-5DB722D44A62}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DC343525-26E7-417E-9140-5DB722D44A62}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DC343525-26E7-417E-9140-5DB722D44A62}.Release|Any CPU.Build.0 = Release|Any CPU {60C2824A-17C1-4019-8749-65AE0448E5B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {60C2824A-17C1-4019-8749-65AE0448E5B3}.Debug|Any CPU.Build.0 = Debug|Any CPU {60C2824A-17C1-4019-8749-65AE0448E5B3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -90,5 +86,9 @@ Global {9963EC55-AADF-4940-AE11-EBCD9F372920}.Debug|Any CPU.Build.0 = Debug|Any CPU {9963EC55-AADF-4940-AE11-EBCD9F372920}.Release|Any CPU.ActiveCfg = Release|Any CPU {9963EC55-AADF-4940-AE11-EBCD9F372920}.Release|Any CPU.Build.0 = Release|Any CPU + {18DCD2E1-CF25-4FAA-816A-3CFB316DD39F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18DCD2E1-CF25-4FAA-816A-3CFB316DD39F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18DCD2E1-CF25-4FAA-816A-3CFB316DD39F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18DCD2E1-CF25-4FAA-816A-3CFB316DD39F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/sources/Server.Application/Users/GetUsersUserCase.cs b/sources/Server.Application/Users/GetUsersUserCase.cs new file mode 100644 index 0000000..a7483d1 --- /dev/null +++ b/sources/Server.Application/Users/GetUsersUserCase.cs @@ -0,0 +1,22 @@ +using MadWorldNL.Server.Domain.Users; + +namespace MadWorldNL.Server.Application.Users; + +public class GetUsersUserCase +{ + private readonly IUserRepository _userRepository; + + public GetUsersUserCase(IUserRepository userRepository) + { + _userRepository = userRepository; + } + public IReadOnlyList GetUsers(int page) + { + if (page < 0) + { + page = 0; + } + + return _userRepository.GetUsers(page); + } +} \ No newline at end of file diff --git a/sources/Server.Domain/Users/IUserRepository.cs b/sources/Server.Domain/Users/IUserRepository.cs index a822c26..52306e6 100644 --- a/sources/Server.Domain/Users/IUserRepository.cs +++ b/sources/Server.Domain/Users/IUserRepository.cs @@ -5,4 +5,5 @@ public interface IUserRepository Task AddRefreshToken(RefreshToken token); Task GetRefreshToken(string token); Task> GetRoles(); + IReadOnlyList GetUsers(int page); } \ No newline at end of file diff --git a/sources/Server.Infrastructure/Database/Users/UserRepository.cs b/sources/Server.Infrastructure/Database/Users/UserRepository.cs index 22aaf39..60fd67f 100644 --- a/sources/Server.Infrastructure/Database/Users/UserRepository.cs +++ b/sources/Server.Infrastructure/Database/Users/UserRepository.cs @@ -40,4 +40,15 @@ public async Task> GetRoles() .Select(x => x.Name!) .ToListAsync(); } + + public IReadOnlyList GetUsers(int page) + { + const int pageSize = 10; + + return _context.Users + .AsNoTracking() + .Skip(page * pageSize) + .Take(pageSize) + .ToList(); + } } \ No newline at end of file diff --git a/sources/Server.Presentation.Grpc/Extensions/WebApplicationBuilderExtensions.cs b/sources/Server.Presentation.Grpc/Extensions/WebApplicationBuilderExtensions.cs index de6d658..bb4ca38 100644 --- a/sources/Server.Presentation.Grpc/Extensions/WebApplicationBuilderExtensions.cs +++ b/sources/Server.Presentation.Grpc/Extensions/WebApplicationBuilderExtensions.cs @@ -15,6 +15,7 @@ public static void AddIdentityMadWorldNL(this WebApplicationBuilder builder) builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/sources/Server.Presentation.Grpc/Mappers/Authentication/GetUsersResponseMappers.cs b/sources/Server.Presentation.Grpc/Mappers/Authentication/GetUsersResponseMappers.cs new file mode 100644 index 0000000..33cbdf2 --- /dev/null +++ b/sources/Server.Presentation.Grpc/Mappers/Authentication/GetUsersResponseMappers.cs @@ -0,0 +1,25 @@ +using MadWorldNL.Server.Domain.Users; +using Server.Presentation.Grpc.UserManager.V1; + +namespace MadWorldNL.Server.Presentation.Grpc.Mappers.Authentication; + +public static class GetUsersResponseMappers +{ + public static GetUsersResponse ToGetUsersResponse(this IReadOnlyList users) + { + return new GetUsersResponse() + { + Users = { users.Select(ToUser) } + }; + } + + private static User ToUser(this IIdentityUser user) + { + return new User() + { + Id = user.Id, + Email = user.Email, + IsBlocked = user.LockoutEnabled + }; + } +} \ No newline at end of file diff --git a/sources/Server.Presentation.Grpc/Program.cs b/sources/Server.Presentation.Grpc/Program.cs index 74e8d3f..a21298e 100644 --- a/sources/Server.Presentation.Grpc/Program.cs +++ b/sources/Server.Presentation.Grpc/Program.cs @@ -8,8 +8,10 @@ using MadWorldNL.Server.Presentation.Grpc.Extensions; using MadWorldNL.Server.Presentation.Grpc.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Components.Server.Circuits; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.IdentityModel.Tokens; var builder = WebApplication.CreateBuilder(args); diff --git a/sources/Server.Presentation.Grpc/Services/UserManagerService.cs b/sources/Server.Presentation.Grpc/Services/UserManagerService.cs index fe8e787..8ff6dc9 100644 --- a/sources/Server.Presentation.Grpc/Services/UserManagerService.cs +++ b/sources/Server.Presentation.Grpc/Services/UserManagerService.cs @@ -1,6 +1,8 @@ using Grpc.Core; +using MadWorldNL.Server.Application.Users; using MadWorldNL.Server.Application.UserSettings; using MadWorldNL.Server.Domain.Authorizations; +using MadWorldNL.Server.Presentation.Grpc.Mappers.Authentication; using Microsoft.AspNetCore.Authorization; using Server.Presentation.Grpc.UserManager.V1; @@ -11,11 +13,16 @@ public class UserManagerService : UserManager.UserManagerBase { private readonly ILogger _logger; private readonly GetAllRolesUseCase _getAllRolesUseCase; + private readonly GetUsersUserCase _getUsersUserCase; - public UserManagerService(ILogger logger, GetAllRolesUseCase getAllRolesUseCase) + public UserManagerService( + ILogger logger, + GetAllRolesUseCase getAllRolesUseCase, + GetUsersUserCase getUsersUserCase) { _logger = logger; _getAllRolesUseCase = getAllRolesUseCase; + _getUsersUserCase = getUsersUserCase; } public override Task DeleteSessions(DeleteSessionsRequest request, ServerCallContext context) @@ -39,7 +46,8 @@ public override Task GetUser(GetUserRequest request, ServerCall public override Task GetUsers(GetUsersRequest request, ServerCallContext context) { - throw new NotImplementedException(); + var users = _getUsersUserCase.GetUsers(request.Page); + return Task.FromResult(users.ToGetUsersResponse()); } public override Task PatchUser(PatchUserRequest request, ServerCallContext context)