Ansprüche über ModelExtensipons konfigurieren

This commit is contained in:
Developer 02
2025-03-25 13:07:06 +01:00
parent b3e7c1aa99
commit 140f172369
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using DigitalData.UserManager.Application.DTOs.User;
using System.Security.Claims;
namespace DigitalData.UserManager.API.Models;
public static class ModelExtensions
{
public static List<Claim> ToClaimList(this UserReadDto user) => new()
{
new (ClaimTypes.NameIdentifier, user.Id.ToString()),
new (ClaimTypes.Name, user.Username),
new (ClaimTypes.Surname, user.Name ?? ""),
new (ClaimTypes.GivenName, user.Prename ?? ""),
new (ClaimTypes.Email, user.Email ?? "")
};
public static Dictionary<string, object> ToClaimDictionary(this UserReadDto user) => user.ToClaimList().ToDictionary(claim => claim.Type, claim => (object)claim.Value);
}