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
/ApiResourceClaims
orIdentityResourceClaims
depending 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
IdentityResourceClaims
table you should add:Then when the client requests the
profile
scope,phone_number
andemail
claim types will be included inProfileDataRequestContext.RequestedClaimTypes
in theProfileService
.Then inside
ProfileService
you can useProfileDataRequestContext.RequestedClaimTypes
andcontext.AddRequestedClaims
to only add theClaims
the were requested from the client: