-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
231 additions
and
66 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
sources/Clients.Admin/Application/Authentications/GrpcHttpMessageHandler.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
sources/Clients.Admin_Old/Application/Authentications/GrpcHttpMessageHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HttpResponseMessage> 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(); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
sources/Clients.Admin_Old/Application/Authentications/UserService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AuthenticationState> task) | ||
{ | ||
_ = UpdateAuthentication(task); | ||
|
||
async Task UpdateAuthentication(Task<AuthenticationState> 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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
sources/Clients.Admin_Old/Application/Authentications/UserServiceMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...nts.Admin/Components/Layout/NavMenu.razor → ...Admin_Old/Components/Layout/NavMenu.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IIdentityUser> GetUsers(int page) | ||
{ | ||
if (page < 0) | ||
{ | ||
page = 0; | ||
} | ||
|
||
return _userRepository.GetUsers(page); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.