Forum Discussion

Dilli's avatar
Dilli
Regular Visitor
10 months ago

decrypt JWT token to check for payload containing particular key and value using groovy script.

I have a need to decrypt/decode the jwt token generated from test step and i need to validate the payload in it.

I am using the following code:-

 

import com.auth0.jwt.JWT
import com.auth0.jwt.interfaces.DecodedJWT

def jwtToken = 'jwt_token_here'

// Decode the JWT token
DecodedJWT decodedJWT = JWT.decode(jwtToken)

// Get the payload (claims) as a JSON object
def payload = decodedJWT.getClaims()

// Convert the payload to a JSON string
def payloadJson = new groovy.json.JsonBuilder(payload).toPrettyString()

// Print the decoded payload
log.info payloadJson 

is displaying the result like this.

where all the key's values are populated with incorrect data("null":false) instead of actual data.

But the same access token is being decoded properly in https://jwt.io website.

Anything i am missing here while parsing?

Thanks in advance.

 

 

No RepliesBe the first to reply