API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#API Connect
#Applicationintegration
#APIConnect
 View Only
  • 1.  JWT Implementation in API Connect

    Posted 09/01/20 01:30 AM
    Hi All, 
    Has anyone implemented JWT generator and JWT validator in IBM API Connect . 

    I have a requirement where  based on my backend JSON response object , i should generate the JWT and use this JWT the next time when client send the request again. 

    I want to know where exactly shall we pass this response object as an input to JWT generator . 

    Do we have any working sample to share 

    Regards
    Sampath

    ------------------------------
    SAMPATH K
    ------------------------------


  • 2.  RE: JWT Implementation in API Connect

    Posted 09/02/20 03:44 AM
    Edited by Panu Tamminen 09/02/20 03:51 AM
    Hi,

    I think I've done something similar, with following approach, but ymmv (just a draft below, missing error handling etc):

    In the API assemble I have following policies in this order:

    1) Invoke-policy makes a request to backend service, registering response let's say as variable 'backendResponse' (per "Response object variable" -setting under Invoke-policy settings)

    2) Gatewayscript-policy for crafting the private claim, using step #1 response as-is or partly

    // JSON response from backend call
    var backendResponse = apim.getvariable('backendResponse');

    // Constructing custom user claim for JWT token
    var customUserData = {"user": backendResponse.body};
    customUserData.user.newAttributeX = "Y";
    // etc further tweaking


    // Passing in this variable for the JWT-generate step
    apim.setvariable('customUserData', customUserData);


    3) JWT-Generate policy , where the "Private claims" -setting is then referring to variable "customUserData" set in step #2

    Br, Panu
    ​​

    ------------------------------
    Panu Tamminen
    Digia
    ------------------------------