这是indexloc提供的服务,不要输入任何密码
Skip to content

Faulty mapping of UserClaims in IdentityResource, ApiResource and ApiScope #42

@tbureck

Description

@tbureck

When mapping from one of IdentityResource, ApiResource or ApiScope entities to their corresponding models, the UserClaims 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions