Skip to content

Commit

Permalink
fix:IdentityClaim (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
duiapro authored May 8, 2024
1 parent 007387c commit 31f9fe4
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public DefaultUserContext(
var modelRelation = ModelRelationCache.GetOrAdd(userType, (type) =>
{
var constructor = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public)
.FirstOrDefault(c => c.GetParameters().Length == 0) ??
throw new InvalidOperationException($"[{type.Name}] has a parameterless constructor");
.FirstOrDefault(c => c.GetParameters().Length == 0) ??
throw new InvalidOperationException($"[{type.Name}] has a parameterless constructor");
return new CustomizeModelRelation(
InstanceBuilder.CreateInstanceDelegate(constructor),
InstanceBuilder.GetPropertyAndMethodInfoRelations(type));
Expand All @@ -44,7 +44,19 @@ public DefaultUserContext(
if (claimType == null)
continue;

var claimValue = ClaimsPrincipal?.FindClaimValue(claimType);
string? claimValue = null;
if (property.PropertyType != typeof(string) && typeof(System.Collections.IEnumerable).IsAssignableFrom(property.PropertyType))
{
var claimsValues = ClaimsPrincipal?.Claims.Where(claim => claim.Type == claimType)
.Select(claim => claim.Value);
if (claimsValues?.Any() == true)
claimValue = JsonSerializer.Serialize(claimsValues);
}
else
{
claimValue = ClaimsPrincipal?.FindClaimValue(claimType);
}

if (claimValue != null)
{
modelRelation.Setters[property]
Expand Down

0 comments on commit 31f9fe4

Please sign in to comment.