IdentityServer4.Contrib.MongoDB
IdentityServer4.Contrib.MongoDB copied to clipboard
Faulty mapping of UserClaims in IdentityResource, ApiResource and ApiScope
When mapping from one of IdentityResource
, ApiResource
or ApiScope
entities to their corresponding models, the UserClaim
s will not be mapped correctly. Instead of containing a list of claims, the property will contain a single list entry with the claim type being its value.
E.g. IdentityResource
contains claims of type IdentityClaim
. When mapping it, the resulting model will contain a single entry with value "IdentityServer4.MongoDB.Entities.IdentityClaim".
I didn't understand it to all detail, but I think this is because AutoMapper neglects the Select(x => x.Type)
part of the expression determining what to map. Hence, it will try to map a UserClaim
object to string by calling its ToString
method. This results in its FQCN being mapped into the resulting collection.
There are two workarounds for this. Either implement a ToString
method for the claim types or configure AutoMapper to map UserClaim
objects to string by using its Type
property. In a small POC I've chosen the latter because I think this is a pure mapping issue and should be resolved there.
This issue exists for documenting purposes, a PR is already in the making.