File tree 1 file changed +15
-3
lines changed
src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity.Core
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ public DefaultUserContext(
31
31
var modelRelation = ModelRelationCache . GetOrAdd ( userType , ( type ) =>
32
32
{
33
33
var constructor = type . GetConstructors ( BindingFlags . Instance | BindingFlags . Public )
34
- . FirstOrDefault ( c => c . GetParameters ( ) . Length == 0 ) ??
35
- throw new InvalidOperationException ( $ "[{ type . Name } ] has a parameterless constructor") ;
34
+ . FirstOrDefault ( c => c . GetParameters ( ) . Length == 0 ) ??
35
+ throw new InvalidOperationException ( $ "[{ type . Name } ] has a parameterless constructor") ;
36
36
return new CustomizeModelRelation (
37
37
InstanceBuilder . CreateInstanceDelegate ( constructor ) ,
38
38
InstanceBuilder . GetPropertyAndMethodInfoRelations ( type ) ) ;
@@ -44,7 +44,19 @@ public DefaultUserContext(
44
44
if ( claimType == null )
45
45
continue ;
46
46
47
- var claimValue = ClaimsPrincipal ? . FindClaimValue ( claimType ) ;
47
+ string ? claimValue = null ;
48
+ if ( property . PropertyType != typeof ( string ) && typeof ( System . Collections . IEnumerable ) . IsAssignableFrom ( property . PropertyType ) )
49
+ {
50
+ var claimsValues = ClaimsPrincipal ? . Claims . Where ( claim => claim . Type == claimType )
51
+ . Select ( claim => claim . Value ) ;
52
+ if ( claimsValues ? . Any ( ) == true )
53
+ claimValue = JsonSerializer . Serialize ( claimsValues ) ;
54
+ }
55
+ else
56
+ {
57
+ claimValue = ClaimsPrincipal ? . FindClaimValue ( claimType ) ;
58
+ }
59
+
48
60
if ( claimValue != null )
49
61
{
50
62
modelRelation . Setters [ property ]
You can’t perform that action at this time.
0 commit comments