Search code examples
wso2

Consume service or database in WSO2 CustomGatewayJWTGenerator


I wanted to know if it is possible to connect to an external database or service from the CustomGatewayJWTGenerator https://github.com/wso2/samples-apim/blob/master/CustomGatewayJWTGenerator/src/main/java/org/wso2/carbon/test/CustomGatewayJWTGenerator.java

Can we propagate ENV variables to the class, for example with the url of the service to invoke? How to know the service to invoke (depending if sandbox or production)?

Additionaly, is there anyway to access the OAuth scope in this class? Is it possible with JWTValidationInfo scopes?


Solution

  • Yes, you can pass an env value or a system property to this class.

    1. Environment variable: Set the env value to the shell.

    System.getenv("ENDPOINT")

    1. System Property: When starting the server you can set the system property as ./api-manager.sh -DENDPOINT="https://localhost:9090"

    System.getProperty("ENDPOINT")

    • You can get the key type which comes as production or sandbox as follows.

    jwtInfoDto.getKeyType()

    • You can get the scopes from here.

    jwtInfoDto. getJwtValidationInfo().getScopes();