tuitio/IdentityServer.Application/Mappings/MappingProfile.cs

32 lines
956 B
C#
Raw Normal View History

2020-12-20 03:06:43 +02:00
using AutoMapper;
using IdentityServer.Domain.Entities;
using System.Collections.Generic;
2020-12-20 03:06:43 +02:00
using dto = IdentityServer.PublishedLanguage.Dto;
using models = IdentityServer.Domain.Models;
namespace IdentityServer.Application.Mappings
{
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<models.Token, dto.Token>();
CreateMap<models.TokenCore, dto.TokenCore>();
CreateMap<AppUser, dto.TokenCore>()
.ForMember(z => z.Claims, src => src.MapFrom(z => ComposeClaims(z.Claims)));
}
private Dictionary<string, string> ComposeClaims(ICollection<UserClaim> claims)
{
if (claims == null)
return null;
var result = new Dictionary<string, string>();
foreach (var claim in claims)
result.Add(claim.ClaimKey, claim.ClaimValue);
return result;
2020-12-20 03:06:43 +02:00
}
}
}