Choose which details an app receives
Decide which of a user's details each scope releases to apps, point details at your own attribute names, and add scopes of your own.
APIOpenID Connect Core 1.0
When a user signs in to an app with OpenID Connect, the app can learn details about them: name, email, phone. You decide which details each scope releases, and from which attribute each one is read. The app gets only what the scopes it was granted release.
Before you start:
- Who can do it: a realm administrator, in a group that holds
RealmOwner(Delegated administration).RealmViewercan read the settings but not change them. - Where: today this is done through the API; Call the API shows how to get
$CVYUH_SESSION. - First: know the attribute name your users’ detail is held under (here
dept).
Three things you can change
Section titled “Three things you can change”- Which details a scope releases:
scopeClaims. The realm starts with the standard mapping:profilereleases names, username, locale and time zone;emailreleases the email address. - Where each detail comes from:
claimAttributes. By defaultgiven_nameis read fromfirstName,family_namefromlastName,preferred_usernamefromuid,emailfromemailandphone_numberfromtelephoneNumber. If your users’ attributes have other names, point each detail at the right one. - Which details the realm releases at all:
claims. A detail missing here is never released, whatever the scopes say.
A scope you add yourself releases nothing until you map it.
Add a scope and its detail
Section titled “Add a scope and its detail”The example adds a department scope that releases a department detail read from the dept attribute, and puts
details in the ID token. The calls use the admin API; Call the API shows how to get a session.
-
Read the current settings, and note the
ETagthe answer carries:Terminal window curl https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" -
Change them, sending that
ETagasIf-Match, so the write is refused412if someone changed the settings since your read. Send each list as you read it, with the new value added. Maps merge key by key, and the standard entries keep their defaults, so send only the new entries:Terminal window curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H 'If-Match: "<ETag from step 1>"' \-H "Content-Type: application/json" \-d '{"scopes": ["…existing scopes", "department"],"claims": ["…existing claims", "department"],"scopeClaims": { "department": ["department"] },"claimAttributes": { "department": "dept" },"idTokenScopeClaims": true}' -
Let the app ask for the scope: read the client with
GET https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>, then send itsscopesback withdepartmentadded, withPATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>. This list, too, replaces the client’s whole list.
Check it worked
Section titled “Check it worked”Sign in to the app with the department scope and call https://foobar.cvyuh.com/oauth2/userinfo with the access token.
The answer carries department for a user who has a dept attribute. With idTokenScopeClaims on, the ID token
carries it too, so the app needn’t call userinfo.
What the app always sees:
- The ID token names the user (
sub), when and how they signed in, and the session.subis the user’s permanent ID in the realm; it doesn’t change when they change their username. - Userinfo returns the released details. A detail the user doesn’t have is left out.
The change is in the realm’s change history as a PATCHED record on oauth2Settings, before and after: see
Audit → Config in the dashboard.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
412 on the write | Someone changed the settings since your read | Read again and resend with the new ETag |
| Userinfo leaves the detail out | The user has no such attribute, the detail isn’t in claims, or the app wasn’t granted the scope | Check each, in that order |
| The detail is in userinfo but not the ID token | idTokenScopeClaims is off | Turn it on, or have the app call userinfo |
A client’s own scopeClaims is refused | It names a detail the realm’s claims doesn’t offer | Add it to claims first |
| Other apps lost a scope or detail | The scopes or claims list sent replaced the realm’s | Send the lists back whole |
Give one app less
Section titled “Give one app less”An app can receive fewer details than the realm releases, for example a partner app that mustn’t see email. Set the
client’s own scopeClaims: for each scope it names, the app gets that list in place of the realm’s. A scope it
doesn’t name keeps the realm’s. The list may name only details the realm offers in claims; the write is refused
otherwise.
curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \ -H "Content-Type: application/json" \ -d '{ "scopeClaims": { "profile": ["name"] } }'That app’s userinfo and ID token now carry name for profile, and no given_name or family_name. Every other app
is unchanged.
Have userinfo signed
Section titled “Have userinfo signed”Set the client’s userinfoSignedResponseAlg (RS256, ES256, or PS256 where the realm offers it). Its userinfo
answer is then a JWT signed with the realm’s key, naming the realm as iss and the app as aud. The algorithm must be
one the realm lists in keySettings.algorithm.oauth2.idToken; if it isn’t, userinfo fails rather than answering
unsigned. An app that registers itself can ask for it as userinfo_signed_response_alg.
Undo it
Section titled “Undo it”Remove a mapping by sending its key as null: { "scopeClaims": { "department": null } }. A standard key you remove
this way goes back to its default.
Related
Section titled “Related”- OpenID Connect sign-in: ID tokens, userinfo and the claim settings.
- Name users by your own directory’s attributes: which attribute users sign in with.
- Choose how ID tokens are signed: the algorithm per app.