This project includes an implementation of the JWTAccessTokenClaimProvider class to include additional claims to the
JWT access token claim set from the URL parameters in HTTP request's query string.
Important: Since the custom claim values doesn't actually exist in the user store, they won't show up in the ID token or the userinfo response.
- Create a maven project with a custom class implementing the
JWTAccessTokenClaimProviderclass, and overriding thegetAdditionalClaimsmethods. - Add the necessary dependencies in the
pom.xml(e.g.,org.wso2.carbon.identity.inbound.auth.oauth2:org.wso2.carbon.identity.oauth).- The correct dependency versions can be found in the WSO2 Identity Server's
pom.xmlfile in theproduct-isrepository.
- The correct dependency versions can be found in the WSO2 Identity Server's
- Make the Maven project an OSGi bundle by adding the necessary plugins (e.g.,
maven-bundle-pluginandmaven-scr-plugin) and dependencies (e.g.,org.apache.felix.scr.ds-annotations), creating an internal package with a bundle activator class with methods with the necessary OSGi Java annotations (e.g.,@Component,@Activate, and@Deactivate), adding the necessary required OSGi bundle dependencies to theImport-Package, and mapping the remaining configuration as per the project structure. - Include the logic to pull data from the HTTP request wrapper and add it to the returning
Mapobject. - Build the Maven project (e.g.,
mvn clean install).
- Copy the JAR file from the
<PROJECT_HOME>/targetfolder to the<IS_HOME>/repository/components/dropinsdirectory. - Start the WSO2 Identity Server.
- Create a custom attribute for each of the claims you want to add to the JWT claim set.
For example, if you want to add
custom_claim_1andcustom_claim_2, create the attribute with the same name. - Include the new OIDC claims to an existing or new OIDC scope (the application must include the scope in the authorisation/token flow).
- Create a new Service Provider or edit an existing one, and include the OIDC scope in the Service Provider's OIDC scopes.
- As an alternative, you can define the custom OIDC claims under the JWT token issuer access token attributes, which don't require adding the claims to OIDC scopes.
For this component's logs to be printed, you need to do the following steps in to the <IS_HOME>/repository/conf/log4j2.properties file:
- Create a Log4J2 Logger named
org-samplemapped to theorg.samplepackage:logger.org-sample.name = org.sample logger.org-sample.level = DEBUG
- Add the new
org-samplelogger to theloggersvariable:loggers = AUDIT_LOG, . . ., org-sample
. . . WARN {org.sample.token.claim.provider.CustomJWTClaimProvider} - Both client channel and client version are null or empty. Not adding to JWT claim set.
. . . WARN {org.sample.token.claim.provider.CustomJWTClaimProvider} - Client channel is null or empty. Not adding to JWT claim set.
. . . WARN {org.sample.token.claim.provider.CustomJWTClaimProvider} - Client version is null or empty. Not adding to JWT claim set.