How to Pass End-User Attributes to the Backend in WSO2 API Manager

--

  1. Get this sample code and modify the CustomGatewayJWTGenerator.populateStandardClaims() method as below.
@Override
public Map<String, Object> populateStandardClaims(JWTInfoDto jwtInfoDto) {
Map<String, Object> claims = super.populateStandardClaims(jwtInfoDto);
claims.put("custom-attribute", "123");
return claims;
}

2. Run mvn clean install and generate the jar file.

3. Copy CustomGatewayJWTGenerator-1.0-SNAPSHOT.jar to <APIM_HOME>/repository/components/dropins directory.

4. Add following config to the <APIM_HOME>/repository/conf/deployment.toml.

[apim.jwt]
enable = true

[apim.jwt.gateway_generator]
impl = "org.wso2.carbon.test.CustomGatewayJWTGenerator"

5. Start/Restart the server.

6. Create and publish a sample REST API in Publisher.

7. Subscribe and invoke the created API in Devportal.

8. You can see that the custom attribute is passed to the backend by decoding the JWT.

{
...

"custom-attribute": "123",

...
}

Cheers! 😃

--

--

Binod Karunanayake
Binod Karunanayake

Written by Binod Karunanayake

PhD Candidate @RMIT University | Former Software Engineer @WSO2 | BSc Engineering (Hons) University of Moratuwa