32 lines
959 B
C#
32 lines
959 B
C#
using AutoMapper;
|
|
using IdentityServer.Domain.Entities;
|
|
using System.Collections.Generic;
|
|
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, models.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;
|
|
}
|
|
}
|
|
}
|