added debug logging

master
Tudor Stanciu 2020-12-21 01:28:22 +02:00
parent d473fdefbe
commit 7b2c20b09e
3 changed files with 17 additions and 3 deletions

View File

@ -5,7 +5,7 @@
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Debug",
"Microsoft": "Warning", "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information"
} }

View File

@ -3,6 +3,7 @@ using IdentityServer.Application.Commands;
using IdentityServer.Application.Services; using IdentityServer.Application.Services;
using IdentityServer.PublishedLanguage.Dto; using IdentityServer.PublishedLanguage.Dto;
using MediatR; using MediatR;
using Microsoft.Extensions.Logging;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,19 +13,25 @@ namespace IdentityServer.Application.CommandHandlers
{ {
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly ILogger<AuthenticateUserHandler> _logger;
public AuthenticateUserHandler(IUserService userService, IMapper mapper) public AuthenticateUserHandler(IUserService userService, IMapper mapper, ILogger<AuthenticateUserHandler> logger)
{ {
_userService = userService; _userService = userService;
_mapper = mapper; _mapper = mapper;
_logger = logger;
} }
public async Task<Token> Handle(AuthenticateUser command, CancellationToken cancellationToken) public async Task<Token> Handle(AuthenticateUser command, CancellationToken cancellationToken)
{ {
var internalToken = await _userService.Authenticate(command.UserName, command.Password); var internalToken = await _userService.Authenticate(command.UserName, command.Password);
if (internalToken == null) if (internalToken == null)
{
_logger.LogDebug($"Authentication failed for user '{command.UserName}'.");
return null; return null;
}
_logger.LogDebug($"Authentication succeeded for user '{command.UserName}'.");
var token = _mapper.Map<Token>(internalToken); var token = _mapper.Map<Token>(internalToken);
return token; return token;
} }

View File

@ -3,6 +3,7 @@ using IdentityServer.Application.Commands;
using IdentityServer.Application.Services; using IdentityServer.Application.Services;
using IdentityServer.PublishedLanguage.Dto; using IdentityServer.PublishedLanguage.Dto;
using MediatR; using MediatR;
using Microsoft.Extensions.Logging;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,19 +13,25 @@ namespace IdentityServer.Application.CommandHandlers
{ {
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly ILogger<AuthorizeTokenHandler> _logger;
public AuthorizeTokenHandler(IUserService userService, IMapper mapper) public AuthorizeTokenHandler(IUserService userService, IMapper mapper, ILogger<AuthorizeTokenHandler> logger)
{ {
_userService = userService; _userService = userService;
_mapper = mapper; _mapper = mapper;
_logger = logger;
} }
public async Task<User> Handle(AuthorizeToken command, CancellationToken cancellationToken) public async Task<User> Handle(AuthorizeToken command, CancellationToken cancellationToken)
{ {
var appUser = await _userService.Authorize(command.Token); var appUser = await _userService.Authorize(command.Token);
if (appUser == null) if (appUser == null)
{
_logger.LogDebug($"Authorization failed for token '{command.Token}'.");
return null; return null;
}
_logger.LogDebug($"Authorization succeeded for token '{command.Token}'.");
var user = _mapper.Map<User>(appUser); var user = _mapper.Map<User>(appUser);
return user; return user;
} }