From 7b2c20b09e3f0fba749885ed043139a7639a0e25 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Mon, 21 Dec 2020 01:28:22 +0200 Subject: [PATCH] added debug logging --- IdentityServer.Api/appsettings.json | 2 +- .../CommandHandlers/AuthenticateUserHandler.cs | 9 ++++++++- .../CommandHandlers/AuthorizeTokenHandler.cs | 9 ++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/IdentityServer.Api/appsettings.json b/IdentityServer.Api/appsettings.json index 2b50dfe..d907efa 100644 --- a/IdentityServer.Api/appsettings.json +++ b/IdentityServer.Api/appsettings.json @@ -5,7 +5,7 @@ }, "Logging": { "LogLevel": { - "Default": "Information", + "Default": "Debug", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } diff --git a/IdentityServer.Application/CommandHandlers/AuthenticateUserHandler.cs b/IdentityServer.Application/CommandHandlers/AuthenticateUserHandler.cs index 1faefd8..d377094 100644 --- a/IdentityServer.Application/CommandHandlers/AuthenticateUserHandler.cs +++ b/IdentityServer.Application/CommandHandlers/AuthenticateUserHandler.cs @@ -3,6 +3,7 @@ using IdentityServer.Application.Commands; using IdentityServer.Application.Services; using IdentityServer.PublishedLanguage.Dto; using MediatR; +using Microsoft.Extensions.Logging; using System.Threading; using System.Threading.Tasks; @@ -12,19 +13,25 @@ namespace IdentityServer.Application.CommandHandlers { private readonly IUserService _userService; private readonly IMapper _mapper; + private readonly ILogger _logger; - public AuthenticateUserHandler(IUserService userService, IMapper mapper) + public AuthenticateUserHandler(IUserService userService, IMapper mapper, ILogger logger) { _userService = userService; _mapper = mapper; + _logger = logger; } public async Task Handle(AuthenticateUser command, CancellationToken cancellationToken) { var internalToken = await _userService.Authenticate(command.UserName, command.Password); if (internalToken == null) + { + _logger.LogDebug($"Authentication failed for user '{command.UserName}'."); return null; + } + _logger.LogDebug($"Authentication succeeded for user '{command.UserName}'."); var token = _mapper.Map(internalToken); return token; } diff --git a/IdentityServer.Application/CommandHandlers/AuthorizeTokenHandler.cs b/IdentityServer.Application/CommandHandlers/AuthorizeTokenHandler.cs index 1821469..a0036fa 100644 --- a/IdentityServer.Application/CommandHandlers/AuthorizeTokenHandler.cs +++ b/IdentityServer.Application/CommandHandlers/AuthorizeTokenHandler.cs @@ -3,6 +3,7 @@ using IdentityServer.Application.Commands; using IdentityServer.Application.Services; using IdentityServer.PublishedLanguage.Dto; using MediatR; +using Microsoft.Extensions.Logging; using System.Threading; using System.Threading.Tasks; @@ -12,19 +13,25 @@ namespace IdentityServer.Application.CommandHandlers { private readonly IUserService _userService; private readonly IMapper _mapper; + private readonly ILogger _logger; - public AuthorizeTokenHandler(IUserService userService, IMapper mapper) + public AuthorizeTokenHandler(IUserService userService, IMapper mapper, ILogger logger) { _userService = userService; _mapper = mapper; + _logger = logger; } public async Task Handle(AuthorizeToken command, CancellationToken cancellationToken) { var appUser = await _userService.Authorize(command.Token); if (appUser == null) + { + _logger.LogDebug($"Authorization failed for token '{command.Token}'."); return null; + } + _logger.LogDebug($"Authorization succeeded for token '{command.Token}'."); var user = _mapper.Map(appUser); return user; }