OpenID Connect 1.0 (OIDC) claims
Use this extension point to modify and override claims in an ID token
and in the response to a /userinfo
request.
To view the default script, including the available script properties, refer to oidc-claims-extension.js.
To view or modify the default script in the Advanced Identity Cloud admin UI, go to Scripts > Auth Scripts and select OIDC Claims Script.
Custom user info claim examples
Refer to the following sections for example use cases:
These examples require you to have a test end user. You can create one as follows:
|
Add custom claims to the profile scope
Complete the following steps to implement an example user info claims script that adds custom claims to the profile scope:
This example replaces the zoneinfo
and locale
claims with custom claims from end user profile attributes. It uses the /oauth2/userinfo endpoint to inspect the custom claim values.
Create the user info claims script
This task describes how to create a new script to map custom claims.
-
In the Advanced Identity Cloud admin UI, go to Scripts > Auth Scripts > + New Script, and create a new OIDC Claims script.
-
Name the script
Demo OIDC claims
. -
Edit the default JavaScript as follows:
-
In the
utils.setScopeClaimsMap
function call, replace thezoneinfo
andlocale
claims with references to the custom claimscustom_string
andcustom_multivalue
:utils.setScopeClaimsMap({ profile: [ 'name', 'family_name', 'given_name', 'custom_string', 'custom_multivalue' ], email: ['email'], address: ['address'], phone: ['phone_number'] });
-
In the
utils.setClaimResolvers
function call, replace thezoneinfo
andlocale
definitions with definitions for the custom claims:utils.setClaimResolvers({ name: utils.getUserProfileClaimResolver('cn'), family_name: utils.getUserProfileClaimResolver('sn'), given_name: utils.getUserProfileClaimResolver('givenname'), custom_string: utils.getUserProfileClaimResolver('fr-attr-str1'), custom_multivalue: utils.getUserProfileClaimResolver('fr-attr-multi1'), email: utils.getUserProfileClaimResolver('mail'), address: utils.getAddressClaimResolver( // ... utils.getUserProfileClaimResolver('postaladdress') ), phone_number: utils.getUserProfileClaimResolver('telephonenumber')}); });
The attributes
fr-attr-str1
andfr-attr-multi1
are end user profile attributes. You set their values when creating the end user profile.
-
-
Save your changes.
The new user info claims script is now ready to retrieve custom claims for the profile
scope.
Create an OpenID Connect 1.0 relying party account
This OIDC relying party (client) profile overrides the OAuth 2.0 provider settings. The override lets you test the script without affecting ID and access tokens issued to other applications.
Refer to Register a client application for further information.
Create a confidential OAuth 2.0 client account
-
In the Advanced Identity Cloud admin UI, go to Applications and click + Custom Application.
-
Select the sign-in method as OIDC - OpenId Connect and application type as Web.
-
Create the application, providing the following details:
- Name
-
myClient
- Owners
-
<resource-owner>
- Client ID
-
myClient
- Client Secret
-
mySecret
-
Switch to the Sign On tab and under General Settings, make the following changes:
- Sign-in URLs
-
https://www.example.com:443/callback
- Grant Types
-
Implicit
- Scopes
-
openid
profile
-
Click Show advanced settings, select the Access tab and make the following changes:
- Response Types
-
token id_token
-
Select the Authentication tab and make the following changes:
- Token Endpoint Authentication Method
-
None
-
Save your changes.
Override OAuth 2.0 provider settings for this client
-
Under Native Consoles > Access Management, select Realms > alpha > Applications > OAuth 2.0 > Clients > myClient, switch to the OAuth2 Provider Overrides tab and update the following settings:
- Enable OAuth2 Provider Overrides
-
Enabled
- OIDC Claims Plugin Type
-
SCRIPTED
- OIDC Claims Script
-
Demo OIDC claims
-
Save your changes.
Update the end user profile
The end user profile holds the values for the custom attributes referenced in your script.
-
In the Advanced Identity Cloud admin UI, go to Identities > Manage > Alpha realm - Users, and select your test user.
-
Update the following settings in your test end user profile and save your work:
- Generic Unindexed String 1
-
Custom string
- Generic Unindexed Multivalue 1
-
custom
value
The script takes custom claim values from the attributes
fr-attr-str1
andfr-attr-multi1
. As described in User identity attributes and properties reference, the Advanced Identity Cloud admin UI labels these Generic Unindexed String 1 and Generic Unindexed Multivalue 1. -
Display the Raw JSON for the end user profile.
Find the following settings in the JSON:
{ "frUnindexedString1": "Custom string", "frUnindexedMultivalued1": [ "custom", "value" ] }
The attributes
fr-attr-str1
andfr-attr-multi1
map tofrUnindexedString1
andfrUnindexedMultivalued1
in the JSON representation.
Try the custom user info claims plugin script
To try your custom script, use the Implicit grant flow as demonstrated in the following steps.
-
Authenticate as the end user:
$ curl \ --request POST \ --header 'Content-Type: application/json' \ --header 'X-OpenAM-Username: <end-user-username>' \ --header 'X-OpenAM-Password: <end-user-password>' \ --header 'Accept-API-Version: resource=2.0, protocol=1.0' \ 'https://<tenant-env-fqdn>/am/json/realms/root/realms/alpha/authenticate' { "tokenId": "<end-user-tokenId>", "successUrl": "/enduser/?realm=/alpha", "realm": "/alpha" }
Copy the value of the
tokenId
returned in the response. You’ll need this value in the next step. -
Invoke the authorization server’s /oauth2/authorize endpoint specifying the
tokenId
value in a cookie, and the following parameters as a minimum:-
client_id=
myClient
-
response_type=
token id_token
-
scope=
openid profile
-
nonce=your nonce value
-
redirect_uri=
https://www.example.com:443/callback
-
decision=
allow
-
csrf=
<end-user-tokenId>
For example:
$ curl --dump-header - \ --cookie '<session-cookie-name>=<end-user-tokenId>' \ --request POST \ --data 'client_id=myClient' \ --data 'response_type=token id_token' \ --data 'scope=openid profile' \ --data 'state=123abc' \ --data 'nonce=abc123' \ --data 'decision=allow' \ --data 'csrf=<end-user-tokenId>' \ --data 'redirect_uri=https://www.example.com:443/callback' \ 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/authorize'
... Location: https://www.example.com:443/callback#access_token=<access-token>&id_token=<id-token>... ...
Copy the value of the
access_token
appended to the redirection URI in the response. You’ll need this value in the next step. -
-
Call the /oauth2/userinfo endpoint to inspect the custom claim values, including the access token obtained from the previous request.
For example:
$ curl \ --request GET \ --header 'Authorization: Bearer <access-token>' \ 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/userinfo' { "name": "Test User", "family_name": "User", "given_name": "Test", "custom_string": "Custom string", "custom_multivalue": ["value", "custom"], "sub": "014c54bd-6078-4639-8316-8ce0e7746fa4", "subname": "014c54bd-6078-4639-8316-8ce0e7746fa4" }
Verify the response contains the custom claim added by the script (
custom_string
andcustom_multivalue
in this example).
Add a custom claim to a custom scope
Complete the following steps to implement an example user info claims script that adds a custom claim to a custom scope:
This example adds the custom claim to the ID token and uses the /oauth2/idtokeninfo endpoint to inspect the custom claim values.
Create the user info claims script
This task describes how to create a new script to map a custom claim.
-
In the Advanced Identity Cloud admin UI, go to Scripts > Auth Scripts > + New Script, and create a new OIDC Claims script.
-
Name the script
Demo OIDC claims
. -
Edit the default JavaScript as follows:
-
In the
utils.setScopeClaimsMap
function call, add the newmyCustomAttr
claim to a newcustom
scope:utils.setScopeClaimsMap({ ... phone: ['phone_number'], custom: ['myCustomAttr']
-
In the
utils.setClaimResolvers
function call, add the new claim to the script. For example, insertmyCustomAttr
after thephone_number
claim as follows:utils.setClaimResolvers({ ... phone_number: utils.getUserProfileClaimResolver('telephonenumber'), myCustomAttr: utils.getUserProfileClaimResolver('uid') });
-
-
Save your changes.
The new user info claims script is now ready to retrieve a custom claim for the custom
scope.
Create an OpenID Connect 1.0 relying party account
This OIDC relying party (client) profile overrides the OAuth 2.0 provider settings. The override lets you test the script without affecting ID and access tokens issued to other applications.
Create a confidential OAuth 2.0 client account
-
In the Advanced Identity Cloud admin UI, go to Applications and click + Custom Application.
-
Select the sign-in method as OIDC - OpenId Connect and application type as Web.
-
Create the application with the following settings:
- Client ID
-
myClient
- Client Secret
-
mySecret
-
Switch to the Sign On tab and under General Settings, make the following changes:
- Sign-in URLs
-
https://www.example.com:443/callback
- Grant Types
-
Implicit
- Scopes
-
openid
profile
custom
-
Click Show advanced settings, select the Access tab and make the following changes:
- Response Types
-
token id_token
-
Select the Authentication tab and make the following changes:
- Token Endpoint Authentication Method
-
None
-
Save your changes.
Override OAuth 2.0 provider settings for this client
-
Under Native Consoles > Access Management, select Realms > alpha > Applications > OAuth 2.0 > Clients > myClient, switch to the OAuth2 Provider Overrides tab and update the following settings:
- Enable OAuth2 Provider Overrides
-
Enabled
- OIDC Claims Plugin Type
-
SCRIPTED
- OIDC Claims Script
-
Demo OIDC claims
-
Save your changes.
Configure the provider to return claims in the ID token
Perform this task to configure the OAuth2 provider to always return scope-derived claims in the ID token.
This option is disabled by default because of the security concerns of returning claims that may contain sensitive user information. Learn more in Request claims in ID tokens. |
-
Under Native Consoles > Access Management, select Realms > alpha > Services > OAuth2 Provider > Advanced OpenID Connect.
-
Enable Always Return Claims in ID Tokens.
-
Save your changes.
Try the custom user info claims plugin script
To try your custom script, use the Implicit grant flow as demonstrated in the following steps.
-
Authenticate as the end user:
$ curl \ --request POST \ --header 'Content-Type: application/json' \ --header 'X-OpenAM-Username: <end-user-username>' \ --header 'X-OpenAM-Password: <end-user-password>' \ --header 'Accept-API-Version: resource=2.0, protocol=1.0' \ 'https://<tenant-env-fqdn>/am/json/realms/root/realms/alpha/authenticate' { "tokenId": "<end-user-tokenId>", "successUrl": "/enduser/?realm=/alpha", "realm": "/alpha" }
Copy the value of the
tokenId
returned in the response. You’ll need this value in the next step. -
Invoke the authorization server’s /oauth2/authorize endpoint specifying the
tokenId
value in a cookie, and the following parameters as a minimum:-
client_id=
myClient
-
response_type=
token id_token
-
scope=
openid profile custom
-
nonce=your nonce value
-
redirect_uri=
https://www.example.com:443/callback
-
decision=
allow
-
csrf=
<end-user-tokenId>
For example:
$ curl --dump-header - \ --cookie '<session-cookie-name>=<end-user-tokenId>' \ --request POST \ --data 'client_id=myClient' \ --data 'response_type=token id_token' \ --data 'scope=openid profile custom' \ --data 'state=123abc' \ --data 'nonce=abc123' \ --data 'decision=allow' \ --data 'csrf=<end-user-tokenId>' \ --data 'redirect_uri=https://www.example.com:443/callback' \ 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/authorize'
... Location: https://www.example.com:443/callback#access_token=<access-token>&id_token=<id-token>... ...
Copy the value of the
id_token
appended to the redirection URI in the response. You’ll need this value in the next step. -
-
Call the /oauth2/idtokeninfo endpoint to inspect the custom claim values, including the ID token obtained from the previous request.
For example:
$ curl \ --request POST \ --user myClient:mySecret \ --data 'id_token=<id-token>' \ "https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/idtokeninfo" { "at_hash": "_0Uie6DRQNgxqiSFa4EIDg", "sub": "014c54bd-6078-4639-8316-8ce0e7746fa4", "auditTrackingId": "b187bfdc-c0ff-4942-b4be-34a8c7134c40-3099380", "subname": "014c54bd-6078-4639-8316-8ce0e7746fa4", "iss": "https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha", "tokenName": "id_token", "given_name": "Test", "sid": "f1ChiEDjsYqYc/ML20bm4QZ9kQvmbIJmD+hZwkRdfOo=", "myCustomAttr":"test.user", "aud": "myClient", "c_hash": "j0ry4449CY9GonHxNEgC4A", "acr": "0", "org.forgerock.openidconnect.ops": "5NkCJhSacAzRsdELBgRJvbpuVMk", "s_hash": "bKE9UspwyIPg8LsQHkJaiQ", "azp": "myClient", "auth_time": 1670316296, "name": "Test User", "realm": "/alpha", "exp": 1670319945, "tokenType": "JWTToken", "iat": 1670316345, "family_name": "User" }
Verify the response contains the custom claim added by the script (
myCustomAttr
in this example).
Add a session property claim to the profile scope
Complete the following steps to implement an example user info claims script that adds a session property claim to the profile scope:
This example adds SSO session details to the ID token and uses the /oauth2/idtokeninfo endpoint to inspect the session property claim values.
These steps add the For an example of adding a session property obtained during a login journey, refer to How do I make session properties from a journey available in the OIDC ID token in Identity Cloud? |
Create the user info claims script
This task describes how to create a new script to map a session property claim.
-
In the Advanced Identity Cloud admin UI, go to Scripts > Auth Scripts > + New Script, and create a new OIDC Claims script.
-
Name the script
Demo OIDC claims
. -
Edit the default JavaScript as follows:
-
In the
utils.setScopeClaimsMap
function call, add the newAuthLevel
claim to theprofile
scope:utils.setScopeClaimsMap({ profile: [ 'name', 'family_name', 'given_name', 'zoneinfo', 'locale', 'AuthLevel' ], email: ['email'],
-
In the
utils.setClaimResolvers
function call, add the new claim to the script. For example, insertAuthLevel
after thephone_number
claim as follows:utils.setClaimResolvers({ ... phone_number: utils.getUserProfileClaimResolver('telephonenumber'), AuthLevel: function () { return session.getProperty('AuthLevel'); } });
-
-
Save your changes.
The new user info claims script is now ready to retrieve a session property claim for the profile
scope.
Allowlist the session property
Provide access to the session property to allow it to be output in the ID token.
-
Under Native Consoles > Access Management, select Realms > alpha > Services > Session Property Whitelist Service.
-
Add
AuthLevel
to the Allowlisted Session Property Names field. -
Save your changes.
Create an OpenID Connect 1.0 relying party account
This OIDC relying party (client) profile overrides the OAuth 2.0 provider settings. The override lets you test the script without affecting ID and access tokens issued to other applications.
Refer to Register a client application for further information.
Create a confidential OAuth 2.0 client account
-
In the Advanced Identity Cloud admin UI, go to Applications and click + Custom Application.
-
Select the sign-in method as OIDC - OpenId Connect and application type as Web.
-
Create the application, providing the following details:
- Name
-
myClient
- Owners
-
<resource-owner>
- Client ID
-
myClient
- Client Secret
-
mySecret
-
Switch to the Sign On tab and under General Settings, make the following changes:
- Sign-in URLs
-
https://www.example.com:443/callback
- Grant Types
-
Implicit
- Scopes
-
openid
profile
-
Click Show advanced settings, select the Access tab and make the following changes:
- Response Types
-
token id_token
-
Select the Authentication tab and make the following changes:
- Token Endpoint Authentication Method
-
None
-
Save your changes.
Override OAuth 2.0 provider settings for this client
-
Under Native Consoles > Access Management, select Realms > alpha > Applications > OAuth 2.0 > Clients > myClient, switch to the OAuth2 Provider Overrides tab and update the following settings:
- Enable OAuth2 Provider Overrides
-
Enabled
- OIDC Claims Plugin Type
-
SCRIPTED
- OIDC Claims Script
-
Demo OIDC claims
-
Save your changes.
Configure the provider to return claims in the ID token
Perform this task to configure the OAuth2 provider to always return scope-derived claims in the ID token.
This option is disabled by default because of the security concerns of returning claims that may contain sensitive user information. Learn more in Request claims in ID tokens. |
-
Under Native Consoles > Access Management, select Realms > alpha > Services > OAuth2 Provider > Advanced OpenID Connect.
-
Enable Always Return Claims in ID Tokens.
-
Save your changes.
Try the custom user info claims plugin script
To try your custom script, use the Implicit grant flow as demonstrated in the following steps.
-
Authenticate as the end user:
$ curl \ --request POST \ --header 'Content-Type: application/json' \ --header 'X-OpenAM-Username: <end-user-username>' \ --header 'X-OpenAM-Password: <end-user-password>' \ --header 'Accept-API-Version: resource=2.0, protocol=1.0' \ 'https://<tenant-env-fqdn>/am/json/realms/root/realms/alpha/authenticate' { "tokenId": "<end-user-tokenId>", "successUrl": "/enduser/?realm=/alpha", "realm": "/alpha" }
Copy the value of the
tokenId
returned in the response. You’ll need this value in the next step. -
Invoke the authorization server’s /oauth2/authorize endpoint specifying the
tokenId
value in a cookie, and the following parameters as a minimum:-
client_id=
myClient
-
response_type=
token id_token
-
scope=
openid profile
-
nonce=your nonce value
-
redirect_uri=
https://www.example.com:443/callback
-
decision=
allow
-
csrf=
<end-user-tokenId>
For example:
$ curl --dump-header - \ --cookie '<session-cookie-name>=<end-user-tokenId>' \ --request POST \ --data 'client_id=myClient' \ --data 'response_type=token id_token' \ --data 'scope=openid profile' \ --data 'state=123abc' \ --data 'nonce=abc123' \ --data 'decision=allow' \ --data 'csrf=<end-user-tokenId>' \ --data 'redirect_uri=https://www.example.com:443/callback' \ 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/authorize'
... Location: https://www.example.com:443/callback#access_token=<access-token>&id_token=<id-token>... ...
Copy the value of the
id_token
appended to the redirection URI in the response. You’ll need this value in the next step. -
-
Call the /oauth2/idtokeninfo endpoint to inspect the session property claim values, including the ID token obtained from the previous request.
For example:
$ curl \ --request POST \ --user myClient:mySecret \ --data 'id_token=<id-token>' \ "https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/idtokeninfo" { "at_hash": "_0Uie6DRQNgxqiSFa4EIDg", "sub": "014c54bd-6078-4639-8316-8ce0e7746fa4", "auditTrackingId": "b187bfdc-c0ff-4942-b4be-34a8c7134c40-3099380", "subname": "014c54bd-6078-4639-8316-8ce0e7746fa4", "iss": "https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha", "tokenName": "id_token", "given_name": "Test", "sid": "f1ChiEDjsYqYc/ML20bm4QZ9kQvmbIJmD+hZwkRdfOo=", "AuthLevel":"0", "aud": "myClient", "c_hash": "j0ry4449CY9GonHxNEgC4A", "acr": "0", "org.forgerock.openidconnect.ops": "5NkCJhSacAzRsdELBgRJvbpuVMk", "s_hash": "bKE9UspwyIPg8LsQHkJaiQ", "azp": "myClient", "auth_time": 1670316296, "name": "Test User", "realm": "/alpha", "exp": 1670319945, "tokenType": "JWTToken", "iat": 1670316345, "family_name": "User" }
Verify the response contains the session property claim added by the script (
AuthLevel
in this example).
Redirect users to a specific URL after they sign out
Complete the following steps to implement an example user info claims script that redirects users to a specific URL after they sign out of the Advanced Identity Cloud end-user UI:
This is achieved by adding an optional claim called post_logout_url
to the OIDC ID token issued during an OIDC flow.
Configure the user info claims script
This task describes how to modify the default script used by the end-user UI to redirect users to a specific URL after they sign out.
-
In the Advanced Identity Cloud admin UI, go to Scripts > Auth Scripts and select Alpha endUserUIClient OIDC Claims Script.
-
Edit the default JavaScript as follows:
-
In the
utils.setScopeClaimsMap
function call, add thepost_logout_url
claim to thefr:idm:*
scope as follows:utils.setScopeClaimsMap({ ... phone: ['phone_number'], 'fr:idm:*': ['post_logout_url']
-
In the
utils.setClaimResolvers
function call, add mapping details for thepost_logout_url
claim, including the URL where you want to redirect users on logout. For example, redirect users to https://pingidentity.com as follows:utils.setClaimResolvers({ ... phone_number: utils.getUserProfileClaimResolver('telephonenumber'), post_logout_url: function (requestedClaim) { return 'https://pingidentity.com'; } });
-
-
Save your changes.
The post_logout_url
claim is added to all clients that use the modified script and request the fr:idm:*
scope.
Configure the provider to return claims in the ID token
Perform this task to configure the OAuth2 provider to always return scope-derived claims in the ID token.
This option is disabled by default because of the security concerns of returning claims that may contain sensitive user information. Learn more in Request claims in ID tokens. |
-
Under Native Consoles > Access Management, select Realms > alpha > Services > OAuth2 Provider > Advanced OpenID Connect.
-
Enable Always Return Claims in ID Tokens.
-
Save your changes.
Test the redirection
Test your changes as follows:
-
In the Advanced Identity Cloud admin UI, go to Journeys and click on the
Login
journey. -
In the Preview URL field, click and paste the URL into an Incognito window.
The Sign In page displays.
-
Sign in as the test end user.
-
Sign out.
The End User UI redirects the browser to the URL you configured for the
post_logout_url
claim, in this case, https://pingidentity.com.
Override the audience and issuer claims
Complete the following steps to implement an example user info claims script that overrides the aud
(audience) and iss
(issuer) claims:
This example overrides the aud
and iss
claims in the ID token and uses the /oauth2/idtokeninfo endpoint to inspect the overridden claims.
These steps override the For information about the core OIDC claims, refer to the ID Token data structure. |
Create the user info claims script
This task describes how to create a new script to override the aud
and iss
claims.
-
In the Advanced Identity Cloud admin UI, go to Scripts > Auth Scripts > + New Script, and create a new OIDC Claims script.
-
Name the script
Demo OIDC claims
. -
Edit the default JavaScript as follows:
-
Add the claim override details before the
return computedClaims;
line. You can specify overrides as a string or an array. For example, add aniss
override as a string:computedClaims.put("iss", "https://example.com") return computedClaims;
-
Then add an
aud
override as an array:var audClaim = ["myClient","testClient"]; computedClaims.put("aud", audClaim)
The
aud
override values you specify must correspond to registered clients; otherwise, you’ll see an error when you inspect the claim values.Replace
testClient
in the script above with the ID of another registered OAuth2 client, or create a temporary OAuth2 client calledtestClient
for testing purposes.
-
-
Save your changes.
The new user info claims script is now ready to override claims.
Create an OpenID Connect 1.0 relying party account
This OIDC relying party (client) profile overrides the OAuth 2.0 provider settings. The override lets you test the script without affecting ID and access tokens issued to other applications.
Refer to Register a client application for further information.
Create a confidential OAuth 2.0 client account
-
In the Advanced Identity Cloud admin UI, go to Applications and click + Custom Application.
-
Select the sign-in method as OIDC - OpenId Connect and application type as Web.
-
Create the application, providing the following details:
- Name
-
myClient
- Owners
-
<resource-owner>
- Client ID
-
myClient
- Client Secret
-
mySecret
-
Switch to the Sign On tab and under General Settings, make the following changes:
- Sign-in URLs
-
https://www.example.com:443/callback
- Grant Types
-
Implicit
- Scopes
-
openid
profile
-
Click Show advanced settings, select the Access tab and make the following changes:
- Response Types
-
token id_token
-
Select the Authentication tab and make the following changes:
- Token Endpoint Authentication Method
-
None
-
Save your changes.
Override OAuth 2.0 provider settings for this client
-
Under Native Consoles > Access Management, select Realms > alpha > Applications > OAuth 2.0 > Clients > myClient, switch to the OAuth2 Provider Overrides tab and update the following settings:
- Enable OAuth2 Provider Overrides
-
Enabled
- OIDC Claims Plugin Type
-
SCRIPTED
- OIDC Claims Script
-
Demo OIDC claims
- Overrideable Id_Token Claims
-
aud
iss
-
Save your changes.
Configure the provider to return claims in the ID token
Perform this task to configure the OAuth2 provider to always return scope-derived claims in the ID token.
This option is disabled by default because of the security concerns of returning claims that may contain sensitive user information. Learn more in Request claims in ID tokens. |
-
Under Native Consoles > Access Management, select Realms > alpha > Services > OAuth2 Provider > Advanced OpenID Connect.
-
Enable Always Return Claims in ID Tokens.
-
Save your changes.
Try the custom user info claims plugin script
To try your custom script, use the Implicit grant flow as demonstrated in the following steps.
-
Authenticate as the end user:
$ curl \ --request POST \ --header 'Content-Type: application/json' \ --header 'X-OpenAM-Username: <end-user-username>' \ --header 'X-OpenAM-Password: <end-user-password>' \ --header 'Accept-API-Version: resource=2.0, protocol=1.0' \ 'https://<tenant-env-fqdn>/am/json/realms/root/realms/alpha/authenticate' { "tokenId": "<end-user-tokenId>", "successUrl": "/enduser/?realm=/alpha", "realm": "/alpha" }
Copy the value of the
tokenId
returned in the response. You’ll need this value in the next step. -
Invoke the authorization server’s /oauth2/authorize endpoint specifying the
tokenId
value in a cookie, and the following parameters as a minimum:-
client_id=
myClient
-
response_type=
token id_token
-
scope=
openid profile
-
nonce=your nonce value
-
redirect_uri=
https://www.example.com:443/callback
-
decision=
allow
-
csrf=
<end-user-tokenId>
For example:
$ curl --dump-header - \ --cookie '<session-cookie-name>=<end-user-tokenId>' \ --request POST \ --data 'client_id=myClient' \ --data 'response_type=token id_token' \ --data 'scope=openid profile' \ --data 'state=123abc' \ --data 'nonce=abc123' \ --data 'decision=allow' \ --data 'csrf=<end-user-tokenId>' \ --data 'redirect_uri=https://www.example.com:443/callback' \ 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/authorize'
... Location: https://www.example.com:443/callback#access_token=<access-token>&id_token=<id-token>... ...
Copy the value of the
id_token
appended to the redirection URI in the response. You’ll need this value in the next step. -
-
Call the /oauth2/idtokeninfo endpoint to inspect the overridden claims, including the ID token obtained from the previous request.
For example:
$ curl \ --request POST \ --user myClient:mySecret \ --data 'id_token=<id-token>' \ "https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/idtokeninfo" { "at_hash": "_0Uie6DRQNgxqiSFa4EIDg", "sub": "014c54bd-6078-4639-8316-8ce0e7746fa4", "auditTrackingId": "b187bfdc-c0ff-4942-b4be-34a8c7134c40-3099380", "subname": "014c54bd-6078-4639-8316-8ce0e7746fa4", "iss":"https://example.com", "tokenName": "id_token", "given_name": "Test", "sid": "f1ChiEDjsYqYc/ML20bm4QZ9kQvmbIJmD+hZwkRdfOo=", "aud": [ "myClient", "testClient" ], "c_hash": "j0ry4449CY9GonHxNEgC4A", "acr": "0", "org.forgerock.openidconnect.ops": "5NkCJhSacAzRsdELBgRJvbpuVMk", "s_hash": "bKE9UspwyIPg8LsQHkJaiQ", "azp": "myClient", "auth_time": 1670316296, "name": "Test User", "realm": "/alpha", "exp": 1670319945, "tokenType": "JWTToken", "iat": 1670316345, "family_name": "User" }
Verify the response contains the overridden
iss
andaud
values.
Use a validated script
Test your OIDC claims scripts as you did in the examples. After validating your script with OAuth 2.0 provider overrides in your test client, you can update the OAuth 2.0 provider configuration to use the script in one of the following ways:
-
Under Native Consoles > Access Management, select Realms > Realm Name > Services > OAuth2 Provider, switch to the Plugins tab, edit the OIDC Claims Script, and save your work.
-
In the Advanced Identity Cloud admin UI, select Scripts > Auth Scripts > Realm Name > OIDC Claims Script, and replace the script content with your validated script.
Available objects
PingOne Advanced Identity Cloud injects the following objects into the execution context of a user info claims script:
Binding | Information | ||
---|---|---|---|
|
An object (map) of the default OIDC claims PingOne Advanced Identity Cloud provides. The keys are the claim strings. The values are the claim value objects. |
||
|
An array of string values from the For details, refer to Claims Languages and Scripts in the OpenID Connect Core 1.0 specification. |
||
|
The default OIDC claims PingOne Advanced Identity Cloud provides. An array of claim objects. |
||
|
A read-only object (map) of the following client properties. This is present if PingOne Advanced Identity Cloud identified the client specified in the request.
|
||
|
An HTTP client for making external HTTP requests. |
||
|
An identity PingOne Advanced Identity Cloud can access. For details, refer to AMIdentity. |
||
|
Write a message to the PingOne Advanced Identity Cloud debug log. Always present in all extension scripts. In Advanced Identity Cloud, this corresponds to the Logger names use the format For information about debug logs, refer to Get audit and debug logs. |
||
|
An object (map) of requested claims.
This is empty unless the request includes the Under Native Consoles > Access Management, go to Realms > Realm Name > Services > OAuth2 Provider > Advanced OpenID Connect. Enable Enable "claims_parameter_supported" and save your change. For details about the |
||
|
An array of the requested claims objects. This is empty unless the request includes claims. A claim with a single value means the script should return only that value. |
||
|
A read-only object (map) of the following request properties.
|
||
|
The set of scope strings in the client request. |
||
|
The display name of the script. |
||
|
The user’s session object. For details, refer to SSOToken. |