Skip to content

Commit

Permalink
chore: gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
ychung-mot committed Sep 12, 2024
1 parent fdc74b1 commit 4f3ff84
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions server/StrDss.Api/Authentication/KcJwtBearerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ public KcJwtBearerEvents(ICurrentUser currentUser, IUserService userService, IBc
_logger = logger;
}

public override Task Challenge(JwtBearerChallengeContext context)
{
var username = context.HttpContext.User?.Identity?.Name ?? "Unknown";
var ipAddress = context.HttpContext.Connection.RemoteIpAddress;
var ip = ipAddress == null ? "Unknown" : ipAddress.ToString();

if (!context.HttpContext.Request.Headers.ContainsKey("Authorization"))
{
_logger.LogWarning($"[AUTH] Authentication failed for user '{username}' from IP address '{ip}'. Authorization header is missing.");
}

return base.Challenge(context);
}

public override Task AuthenticationFailed(AuthenticationFailedContext context)
{
var username = context.HttpContext.User?.Identity?.Name ?? "Unknown";
var ipAddress = context.HttpContext.Connection.RemoteIpAddress;
var ip = ipAddress == null ? "Unknown" : ipAddress.ToString();

_logger.LogInformation($"[AUTH] Authentication failed for user '{username}' from IP address '{ip}'.");

return base.AuthenticationFailed(context);
}
//public override Task Challenge(JwtBearerChallengeContext context)
//{
// var username = context.HttpContext.User?.Identity?.Name ?? "Unknown";
// var ipAddress = context.HttpContext.Connection.RemoteIpAddress;
// var ip = ipAddress == null ? "Unknown" : ipAddress.ToString();

// if (!context.HttpContext.Request.Headers.ContainsKey("Authorization"))
// {
// _logger.LogWarning($"[AUTH] Authentication failed for user '{username}' from IP address '{ip}'. Authorization header is missing.");
// }

// return base.Challenge(context);
//}

//public override Task AuthenticationFailed(AuthenticationFailedContext context)
//{
// var username = context.HttpContext.User?.Identity?.Name ?? "Unknown";
// var ipAddress = context.HttpContext.Connection.RemoteIpAddress;
// var ip = ipAddress == null ? "Unknown" : ipAddress.ToString();

// _logger.LogInformation($"[AUTH] Authentication failed for user '{username}' from IP address '{ip}'.");

// return base.AuthenticationFailed(context);
//}

public override async Task TokenValidated(TokenValidatedContext context)
{
Expand Down

0 comments on commit 4f3ff84

Please sign in to comment.