Ask a Question

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

Dilli
Regular Visitor

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.

Dilli_0-1685613943783.png

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.

 

 

0 REPLIES 0
cancel
Showing results for 
Search instead for 
Did you mean: