I would like to be able to issue a phone_number claim xor email claim depending on what is required by the client. I use Identity Server 5(Duende) but the answer will be the same for Identity Server 4.
I understand that I can add a claim to identity token in ProfileService, however how to configure the client in the db so I will be able to check what is required by a client in the profile service?
The additional claims should be configured in either
ApiScopeClaims/ApiResourceClaimsorIdentityResourceClaimsdepending on if the claim should be include in the access token or the id token (could be both).For example you if have:
Then in
IdentityResourceClaimstable you should add:Then when the client requests the
profilescope,phone_numberandemailclaim types will be included inProfileDataRequestContext.RequestedClaimTypesin theProfileService.Then inside
ProfileServiceyou can useProfileDataRequestContext.RequestedClaimTypesandcontext.AddRequestedClaimsto only add theClaimsthe were requested from the client: