authentication result update

master
Tudor Stanciu 2020-12-24 04:39:59 +02:00
parent 7b2c20b09e
commit f17bb6f151
4 changed files with 28 additions and 6 deletions

View File

@ -1,7 +1,9 @@
using AutoMapper; using AutoMapper;
using IdentityServer.Application.Commands; using IdentityServer.Application.Commands;
using IdentityServer.Application.Services; using IdentityServer.Application.Services;
using IdentityServer.PublishedLanguage.Constants;
using IdentityServer.PublishedLanguage.Dto; using IdentityServer.PublishedLanguage.Dto;
using IdentityServer.PublishedLanguage.Events;
using MediatR; using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Threading; using System.Threading;
@ -9,7 +11,7 @@ using System.Threading.Tasks;
namespace IdentityServer.Application.CommandHandlers namespace IdentityServer.Application.CommandHandlers
{ {
public class AuthenticateUserHandler : IRequestHandler<AuthenticateUser, Token> public class AuthenticateUserHandler : IRequestHandler<AuthenticateUser, AuthenticateUserResult>
{ {
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly IMapper _mapper; private readonly IMapper _mapper;
@ -22,18 +24,19 @@ namespace IdentityServer.Application.CommandHandlers
_logger = logger; _logger = logger;
} }
public async Task<Token> Handle(AuthenticateUser command, CancellationToken cancellationToken) public async Task<AuthenticateUserResult> 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}'."); _logger.LogDebug($"Authentication failed for user '{command.UserName}'.");
return null; return new AuthenticateUserResult() { Status = AuthenticationStatus.BAD_CREDENTIALS };
} }
_logger.LogDebug($"Authentication succeeded for user '{command.UserName}'."); _logger.LogDebug($"Authentication succeeded for user '{command.UserName}'.");
var token = _mapper.Map<Token>(internalToken); var token = _mapper.Map<Token>(internalToken);
return token;
return new AuthenticateUserResult() { Token = token, Status = AuthenticationStatus.SUCCESS };
} }
} }
} }

View File

@ -1,9 +1,9 @@
using IdentityServer.PublishedLanguage.Dto; using IdentityServer.PublishedLanguage.Events;
using NDB.Application.DataContracts; using NDB.Application.DataContracts;
namespace IdentityServer.Application.Commands namespace IdentityServer.Application.Commands
{ {
public class AuthenticateUser : Command<Token> public class AuthenticateUser : Command<AuthenticateUserResult>
{ {
public string UserName { get; set; } public string UserName { get; set; }
public string Password { get; set; } public string Password { get; set; }

View File

@ -0,0 +1,9 @@
namespace IdentityServer.PublishedLanguage.Constants
{
public struct AuthenticationStatus
{
public const string
SUCCESS = "SUCCESS",
BAD_CREDENTIALS = "BAD_CREDENTIALS";
}
}

View File

@ -0,0 +1,10 @@
using IdentityServer.PublishedLanguage.Dto;
namespace IdentityServer.PublishedLanguage.Events
{
public class AuthenticateUserResult
{
public Token Token { get; set; }
public string Status { get; set; }
}
}