4
4
using StrDss . Model . UserDtos ;
5
5
using StrDss . Service ;
6
6
using StrDss . Service . Bceid ;
7
+ using System . Net ;
7
8
8
9
namespace StrDss . Api . Authentication
9
10
{
@@ -22,32 +23,34 @@ public KcJwtBearerEvents(ICurrentUser currentUser, IUserService userService, IBc
22
23
_logger = logger ;
23
24
}
24
25
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";
31
32
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
+ // }
45
46
46
- await base . AuthenticationFailed ( context ) ;
47
- }
47
+ // await base.AuthenticationFailed(context);
48
+ // }
48
49
49
50
public override async Task TokenValidated ( TokenValidatedContext context )
50
51
{
52
+ _logger . LogDebug ( $ "[AUTH] Token Validated with KC JWT") ;
53
+
51
54
_currentUser . LoadUserSession ( context ! . Principal ! ) ;
52
55
53
56
var ( user , permissions ) = await _userService . GetUserByGuidAsync ( _currentUser . UserGuid ) ;
0 commit comments