mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 07:16:31 +00:00
26 lines
717 B
C#
26 lines
717 B
C#
using System.Security.Claims;
|
|
using MessagePack;
|
|
|
|
namespace Azaion.CommonSecurity.DTO;
|
|
|
|
[MessagePackObject]
|
|
public class User
|
|
{
|
|
[Key("i")] public string Id { get; set; } = "";
|
|
[Key("e")] public string Email { get; set; } = "";
|
|
[Key("r")]public RoleEnum Role { get; set; }
|
|
|
|
//For deserializing
|
|
public User(){}
|
|
|
|
public User(IEnumerable<Claim> claims)
|
|
{
|
|
var claimDict = claims.ToDictionary(x => x.Type, x => x.Value);
|
|
|
|
Id = claimDict[SecurityConstants.CLAIM_NAME_ID];
|
|
Email = claimDict[SecurityConstants.CLAIM_EMAIL];
|
|
if (!Enum.TryParse(claimDict[SecurityConstants.CLAIM_ROLE], out RoleEnum role))
|
|
role = RoleEnum.None;
|
|
Role = role;
|
|
}
|
|
} |