33 lines
964 B
C#
33 lines
964 B
C#
|
using AutoMapper;
|
|||
|
using IdentityServer.Application.Commands;
|
|||
|
using IdentityServer.Application.Services;
|
|||
|
using IdentityServer.PublishedLanguage.Dto;
|
|||
|
using MediatR;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace IdentityServer.Application.CommandHandlers
|
|||
|
{
|
|||
|
public class AuthorizeTokenHandler : IRequestHandler<AuthorizeToken, User>
|
|||
|
{
|
|||
|
private readonly IUserService _userService;
|
|||
|
private readonly IMapper _mapper;
|
|||
|
|
|||
|
public AuthorizeTokenHandler(IUserService userService, IMapper mapper)
|
|||
|
{
|
|||
|
_userService = userService;
|
|||
|
_mapper = mapper;
|
|||
|
}
|
|||
|
|
|||
|
public async Task<User> Handle(AuthorizeToken command, CancellationToken cancellationToken)
|
|||
|
{
|
|||
|
var appUser = await _userService.Authorize(command.Token);
|
|||
|
if (appUser == null)
|
|||
|
return null;
|
|||
|
|
|||
|
var user = _mapper.Map<User>(appUser);
|
|||
|
return user;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|