Files
mixtape/zero.Core/Entities/User/UserClaim.cs
T

60 lines
1.3 KiB
C#
Raw Normal View History

2020-04-14 20:16:04 +02:00
using System;
using System.Collections.Generic;
using System.Security.Claims;
2020-03-24 20:30:03 +01:00
2020-03-24 23:09:29 +01:00
namespace zero.Core.Entities
2020-03-24 20:30:03 +01:00
{
2021-05-04 17:23:52 +02:00
public class UserClaim
2020-03-24 20:30:03 +01:00
{
2021-05-04 17:23:52 +02:00
/// <summary>
/// Gets or sets the claim type for this claim
/// </summary>
2020-03-24 20:30:03 +01:00
public string Type { get; set; }
2021-05-04 17:23:52 +02:00
/// <summary>
/// Gets or sets the claim value for this claim
/// </summary>
2020-03-24 20:30:03 +01:00
public string Value { get; set; }
2021-05-04 17:23:52 +02:00
/// <summary>
/// Convert to a claim
/// </summary>
2020-03-24 20:30:03 +01:00
public Claim ToClaim() => new Claim(Type, Value);
2020-04-14 20:16:04 +02:00
public UserClaim() { }
public UserClaim(string type, string value)
{
Type = type;
Value = value;
}
public UserClaim(string type, string key, string value)
{
Type = type;
Value = key + ":" + value;
}
2020-04-14 20:16:04 +02:00
public UserClaim(Claim claim)
2020-03-24 20:30:03 +01:00
{
2020-04-14 20:16:04 +02:00
Type = claim?.Type;
Value = claim?.Value;
2020-03-24 20:30:03 +01:00
}
}
2021-05-04 17:23:52 +02:00
public class UserClaimComparer : IEqualityComparer<UserClaim>
2020-03-24 20:30:03 +01:00
{
2021-05-04 17:23:52 +02:00
public bool Equals(UserClaim x, UserClaim y)
2020-04-14 20:16:04 +02:00
{
return (x == null && y == null) || (x.Type.Equals(y.Type, StringComparison.InvariantCultureIgnoreCase) && x.Value.Equals(y.Value, StringComparison.InvariantCultureIgnoreCase));
}
2021-05-04 17:23:52 +02:00
public int GetHashCode(UserClaim obj)
2020-04-14 20:16:04 +02:00
{
return (obj.Type + obj.Value).GetHashCode();
}
}
2020-03-24 20:30:03 +01:00
}