Skip to content
Workforce IdentityMarkdown

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). RealmViewer can 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).
  • Which details a scope releases: scopeClaims. The realm starts with the standard mapping: profile releases names, username, locale and time zone; email releases the email address.
  • Where each detail comes from: claimAttributes. By default given_name is read from firstName, family_name from lastName, preferred_username from uid, email from email and phone_number from telephoneNumber. 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.

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.

  1. Read the current settings, and note the ETag the answer carries:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
  2. Change them, sending that ETag as If-Match, so the write is refused 412 if 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
    }'
  3. 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 its scopes back with department added, with PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>. This list, too, replaces the client’s whole list.

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. sub is 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.

SymptomCauseFix
412 on the writeSomeone changed the settings since your readRead again and resend with the new ETag
Userinfo leaves the detail outThe user has no such attribute, the detail isn’t in claims, or the app wasn’t granted the scopeCheck each, in that order
The detail is in userinfo but not the ID tokenidTokenScopeClaims is offTurn it on, or have the app call userinfo
A client’s own scopeClaims is refusedIt names a detail the realm’s claims doesn’t offerAdd it to claims first
Other apps lost a scope or detailThe scopes or claims list sent replaced the realm’sSend the lists back whole

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.

Terminal window
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.

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.

Remove a mapping by sending its key as null: { "scopeClaims": { "department": null } }. A standard key you remove this way goes back to its default.