tuitio/IdentityServer.Application/CommandHandlers/AuthorizeTokenHandler.cs

33 lines
964 B
C#
Raw Normal View History

2020-12-20 03:06:43 +02:00
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;
}
}
}