Skip to content

Commit 71af44e

Browse files
authored
Merge pull request #631 from bcgov/yj
chore: aps auth
2 parents 528da28 + df4c564 commit 71af44e

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

server/StrDss.Api/Authentication/ApsJwtBearerEvents.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ public ApsJwtBearerEvents(ICurrentUser currentUser, IUserService userService, IR
2525
_memoryCache = memoryCache;
2626
}
2727

28-
public override async Task AuthenticationFailed(AuthenticationFailedContext context)
29-
{
30-
var clientId = context.HttpContext.User?.FindFirst(StrDssClaimTypes.ClientId)?.Value ?? "Unknown";
31-
var ipAddress = context.HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP";
28+
//public override async Task AuthenticationFailed(AuthenticationFailedContext context)
29+
//{
30+
// var clientId = context.HttpContext.User?.FindFirst(StrDssClaimTypes.ClientId)?.Value ?? "Unknown";
31+
// var ipAddress = context.HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP";
3232

33-
clientId = clientId == "" ? "" : clientId;
33+
// clientId = clientId == "" ? "" : clientId;
3434

35-
_logger.LogWarning($"[AUTH] Aps Authentication failed for user '{clientId}' from IP address '{ipAddress}'.");
35+
// _logger.LogWarning($"[AUTH] Aps Authentication failed for user '{clientId}' from IP address '{ipAddress}'.");
3636

37-
await base.AuthenticationFailed(context);
38-
}
37+
// await base.AuthenticationFailed(context);
38+
//}
3939

4040
public override async Task TokenValidated(TokenValidatedContext context)
4141
{
42+
_logger.LogDebug($"[AUTH] Token Validated with APS JWT");
43+
4244
_currentUser.LoadApsSession(context!.Principal!);
4345

4446
var (user, permissions) = await _userService.GetUserByGuidAsync(_currentUser.UserGuid);

server/StrDss.Api/Authentication/KcJwtBearerEvents.cs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using StrDss.Model.UserDtos;
55
using StrDss.Service;
66
using StrDss.Service.Bceid;
7+
using System.Net;
78

89
namespace StrDss.Api.Authentication
910
{
@@ -22,32 +23,34 @@ public KcJwtBearerEvents(ICurrentUser currentUser, IUserService userService, IBc
2223
_logger = logger;
2324
}
2425

25-
public override async Task AuthenticationFailed(AuthenticationFailedContext context)
26-
{
27-
try
28-
{
29-
var username = context.HttpContext.User?.Identity?.Name ?? "Unknown";
30-
var ipAddress = context.HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP";
26+
//public override async Task AuthenticationFailed(AuthenticationFailedContext context)
27+
//{
28+
// try
29+
// {
30+
// var username = context.HttpContext.User?.Identity?.Name ?? "Unknown";
31+
// var ipAddress = context.HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP";
3132

32-
if (!context.HttpContext.Request.Headers.ContainsKey("Authorization"))
33-
{
34-
_logger.LogWarning($"[AUTH] KC Authentication failed for user '{username}' from IP address '{ipAddress}'. Authorization header is missing.");
35-
}
36-
else
37-
{
38-
_logger.LogDebug($"[AUTH] Authorization header present. Proceeding with Aps authentication for user '{username}' from IP address '{ipAddress}'.");
39-
}
40-
}
41-
catch (Exception ex)
42-
{
43-
_logger.LogError(ex, "An error occurred while processing the authentication failure.");
44-
}
33+
// if (!context.HttpContext.Request.Headers.ContainsKey("Authorization"))
34+
// {
35+
// _logger.LogWarning($"[AUTH] KC Authentication failed for user '{username}' from IP address '{ipAddress}'. Authorization header is missing.");
36+
// }
37+
// else
38+
// {
39+
// _logger.LogDebug($"[AUTH] Authorization header present. Proceeding with Aps authentication for user '{username}' from IP address '{ipAddress}'.");
40+
// }
41+
// }
42+
// catch (Exception ex)
43+
// {
44+
// _logger.LogError(ex, "An error occurred while processing the authentication failure.");
45+
// }
4546

46-
await base.AuthenticationFailed(context);
47-
}
47+
// await base.AuthenticationFailed(context);
48+
//}
4849

4950
public override async Task TokenValidated(TokenValidatedContext context)
5051
{
52+
_logger.LogDebug($"[AUTH] Token Validated with KC JWT");
53+
5154
_currentUser.LoadUserSession(context!.Principal!);
5255

5356
var (user, permissions) = await _userService.GetUserByGuidAsync(_currentUser.UserGuid);

0 commit comments

Comments
 (0)