Reputation: 1
I tried to implement the steps given in WSO2 4.0.0 documentation https://apim.docs.wso2.com/en/4.0.0/deploy-and-publish/deploy-on-gateway/api-gateway/passing-enduser-attributes-to-the-backend-via-api-gateway/ for customizing JWT Claims.
As given in the documentation, I created the custom JWT generator java class, generated the jar and placed it under WSO2 Home/repository/components/lib folder . Did the necessary configurations in deployment.toml for enabling JWT and restarted the server.
Need suggestions on this as i have followed the steps given in the documentation.
I execute the examples CustomGatewayJWTGenerator,CustomJWTGenerator
of repo official examples.
{
"sub": "xxxx",
"aut": "xxxx",
"aud": "xxx",
"nbf": xxx,
"azp": "xxx",
"scope": "xxx",
"iss": "xx://xxx:9443/oauth2/token",
"exp": xxxxx,
"iat": xxxxx,
"jti": "xxxx-xxxx-xxx-xxxx-xxxxxx"
//custom
"name:"xxxxx",
"lastname":"xxxx"
}
Upvotes: 0
Views: 297
Reputation: 626
You can customize JWT by adding custom claims using a CustomGatewayJWTGenerator
as in docs. Follow the steps below to test this.
CustomGatewayJWTGenerator.populateStandardClaims()
class as below.@Override
public Map<String, Object> populateStandardClaims(JWTInfoDto jwtInfoDto) {
Map<String, Object> claims = super.populateStandardClaims(jwtInfoDto);
claims.put("custom-attribute", "123");
return claims;
}
mvn clean install
and generate the jar file.CustomGatewayJWTGenerator-1.0-SNAPSHOT.jar
to <APIM_HOME>/repository/components/dropins
directory.<APIM_HOME>/repository/conf/deployment.toml
.[apim.jwt]
enable = true
[apim.jwt.gateway_generator]
impl = "org.wso2.carbon.test.CustomGatewayJWTGenerator"
{
...
"custom-attribute": "123",
...
}
Upvotes: 2