Skip to content

Commit

Permalink
fixing expiry time calculation from jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2307 committed Dec 10, 2024
1 parent 635bd4c commit d130d48
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -318,13 +319,17 @@ public static LoginFlowResponse runLoginFlow(WorkflowTest workflowTest, AuthMech
}
if(KeyTypes.isJWT(tempVal)){
try {
Jws<Claims> jws = Jwts.parserBuilder()
.build()
.parseClaimsJws(tempVal);

if(jws.getBody() != null && jws.getBody().getExpiration() != null && jws.getBody().getExpiration().getTime() != 0){
int newExpiryTime = (int) jws.getBody().getExpiration().getTime();
String[] parts = tempVal.split("\\.");
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid JWT token format");
}
String payload = new String(Base64.getUrlDecoder().decode(parts[1]));
JSONObject payloadJson = new JSONObject(payload);
if (payloadJson.has("exp")) {
int newExpiryTime = payloadJson.getInt("exp");
TestExecutor.setExpiryTimeOfAuthToken(newExpiryTime);
} else {
throw new IllegalArgumentException("JWT does not have an 'exp' claim");
}
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit d130d48

Please sign in to comment.