Introduction
The claims returned by the Userinfo API can be customized with theclaims parameter just like those in How to Add Custom Claims to ID Tokens.
This article explains how to add arbitrary claims to the Userinfo endpoint response and which Authlete features help determine the right claims.
Basic Implementation of the Userinfo Endpoint
When an OpenID Provider builds a Userinfo API endpoint with Authlete, it needs to call the following two APIs:- Userinfo Request /api//auth/userinfo
- Issue Userinfo Response /api//auth/userinfo/issue
Calling the Userinfo Request API
In practice, the OpenID Provider forwards the user’s access token to Authlete’s Userinfo Request API:action is OK, which proves the token is valid. Because the subject is john, the OpenID Provider can collect the attributes linked to john and provide them to the Issue Userinfo Response API.
Calling the Issue Userinfo Response API
Since Authlete does not store attribute values linked to users, the OpenID Provider must prepare the attribute values to be included in the response from the UserInfo endpoint. On the other hand, the OpenID Provider can use the claims parameter returned by Authlete to determine which attributes to include in the UserInfo response. Theclaims parameter contained in the Userinfo Request API response is a merged list of claims derived from the scopes specified at the /auth/authorization endpoint and claims explicitly requested via the claims parameter, just like the logic described in Determining Claims to Add to an ID Token.
In the previous example, the requested scope included openid and email, so the email scope expanded to email and email_verified, and both claims appeared in the claims array. For the list of scopes and their corresponding claims, refer to the Authlete Java Common Javadoc ClaimsScope.
Below is an example where the OpenID Provider injects the following claims from Authlete’s claims response into the Userinfo payload:
| Claim | Value |
|---|---|
| ”email" | "john@example.com" |
| "email_verified” | true |
responseContent:
Customizing the List of Claims to Include
Theclaims array calculated by Authlete follows OpenID Connect Core, but it may not match real-world requirements. For example, you might need to return a different set of claims from the Userinfo endpoint than from the ID token, or you may accept only the openid and email scopes while still needing to send additional user-consented claims in the Userinfo response.
In that case, the OpenID Provider can leverage consentedClaims to propagate the claims that the end-user allowed the RP to access at the authorization endpoint to both the Introspection and Userinfo endpoints.
consentedClaimsis available in Authlete 2.3 and later. For details onconsentedClaims, please refer to the Authlete JavaDoc: AuthorizationIssueRequest.html#setConsentedClaims().
Telling Authlete Which Claims the User Consented To
Assume that during authorization the user agreed to share their full name, username, and email address with the RP, and the OpenID Provider wants to return those attributes from the Userinfo endpoint. The authorization endpoint first sends the following request to Authlete and receives a ticket:auth/authorization/issue endpoint. It passes consentedClaims with name, username, email, and email_verified.
consentedClaims specified at authorization time and later includes them in the responses from /auth/userinfo and /auth/introspection.
Ensure that any claim you plan to list in>consentedClaimshas already been registered under the target service’sTokens & Claims>Claims>Supported Claimssettings.
Using Consented Claims in the Userinfo API Response
When the access token tied to the above authorization flow is sent to the Userinfo Request API, the response is as follows:claims array, the OpenID Provider can use the consentedClaims array and return the claims the user agreed to share as the Userinfo endpoint payload.
