authentication result update
parent
7b2c20b09e
commit
f17bb6f151
|
@ -1,7 +1,9 @@
|
|||
using AutoMapper;
|
||||
using IdentityServer.Application.Commands;
|
||||
using IdentityServer.Application.Services;
|
||||
using IdentityServer.PublishedLanguage.Constants;
|
||||
using IdentityServer.PublishedLanguage.Dto;
|
||||
using IdentityServer.PublishedLanguage.Events;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
|
@ -9,7 +11,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace IdentityServer.Application.CommandHandlers
|
||||
{
|
||||
public class AuthenticateUserHandler : IRequestHandler<AuthenticateUser, Token>
|
||||
public class AuthenticateUserHandler : IRequestHandler<AuthenticateUser, AuthenticateUserResult>
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
private readonly IMapper _mapper;
|
||||
|
@ -22,18 +24,19 @@ namespace IdentityServer.Application.CommandHandlers
|
|||
_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);
|
||||
if (internalToken == null)
|
||||
{
|
||||
_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}'.");
|
||||
var token = _mapper.Map<Token>(internalToken);
|
||||
return token;
|
||||
|
||||
return new AuthenticateUserResult() { Token = token, Status = AuthenticationStatus.SUCCESS };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using IdentityServer.PublishedLanguage.Dto;
|
||||
using IdentityServer.PublishedLanguage.Events;
|
||||
using NDB.Application.DataContracts;
|
||||
|
||||
namespace IdentityServer.Application.Commands
|
||||
{
|
||||
public class AuthenticateUser : Command<Token>
|
||||
public class AuthenticateUser : Command<AuthenticateUserResult>
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
namespace IdentityServer.PublishedLanguage.Constants
|
||||
{
|
||||
public struct AuthenticationStatus
|
||||
{
|
||||
public const string
|
||||
SUCCESS = "SUCCESS",
|
||||
BAD_CREDENTIALS = "BAD_CREDENTIALS";
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue