Creating JWT custom claims in DataPower

1.7k views Asked by At

Running on DataPower 7.5.2.0

I created a JWT Generator as part of a AAA Policy and it is working fine, I am able to generate, sign and then externally verify the JWT with no issues.

Now I want to add a custom claim to the JWT, so I ticked the box for Custom and then uploaded this Gateway script file:

var claim = {
    "result" : {
        "user" : "hardcode"
    }
};
session.output.write(claim);

and it generates the correct JWT with the user attribute. However when I try to add a second value to it like so:

var claim = {
    "result" : {
        "user" : "hardcode",
        "name" : "myname"
    }
};
session.output.write(claim);

I now get this error:

[Error: Required CustomClaim Name or Value field missing] errorMessage: 'Required CustomClaim Name or Value field missing', errorCode: '0x8580005c', errorDescription: 'GatewayScript console log message.', errorSuggestion: 'GatewayScript console log message. Refer to the message for more information.'

Which is the same message I got before I realized I had to set the output to result from the InfoCenter's vague documentation.

How do I add multiple custom claims in the JWT Generator Gateway script??

1

There are 1 answers

0
Devin Richards On

It would appear that DataPower only allows you to add a single custom claim, so you just need to make that a complex object like so:

var claim = {
    "result" : {
        "claim" : {
            "user" : "hardcode",
            "one" : true,
            "clientId" : "asdf-asdf-asdf",
            "endpoint" : "http://192.168.142:8080/member/ws"
        }
    }
};
session.output.write(claim);

This then generates the correct JWT with a nest claim.

eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGljIiwic3ViIjoiYWRtaW4iLCJleHAiOjE0ODIyNjU5ODQsImlhdCI6MTQ4MjI2MjM4NCwianRpIjoiZDhjNTE1ZDEtZmVjMS00ZGVmLThiNDctZmYzY2E2OWVjOWRiIiwibm9uY2UiOiJtN2lVZlBqTCIsImF1ZCI6ImlkMSIsImNsYWltIjp7InVzZXIiOiJmcmVkIiwib25lIjp0cnVlLCJjbGllbnRJZCI6ImFzZGYtYXNkZi1hc2RmIiwiZW5kcG9pbnQiOiJodHRwOi8vMTkyLjE2OC4xNDI6ODA4MC9tZW1iZXIvd3MifX0.viakwnM5bhhmGIn0QmDJTmsWCuIciO2BOdUVyxYpsFA