Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 2d9dc89

Browse files
authored
Manage JWTCreator get token parts exceptions (#35)
1 parent b431ebc commit 2d9dc89

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

GeneXusJWT/src/main/java/com/genexus/JWT/JWTCreator.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,38 @@ public boolean doVerifySignature(String token, String expectedAlgorithm, JWTOpti
109109
}
110110

111111
public String getPayload(String token) {
112-
return getTokenPart(token, "payload");
112+
String res = "";
113+
try {
114+
res = getTokenPart(token, "payload");
115+
} catch (Exception e) {
116+
this.error.setError("JW009", e.getMessage());
117+
return "";
118+
}
119+
return res;
113120

114121
}
115122

116123
public String getHeader(String token) {
117-
return getTokenPart(token, "header");
124+
String res = "";
125+
try {
126+
res = getTokenPart(token, "header");
127+
} catch (Exception e) {
128+
this.error.setError("JW010", e.getMessage());
129+
return "";
130+
}
131+
return res;
118132
}
119133

120134
public String getTokenID(String token) {
121-
return getTokenPart(token, "id");
135+
String res = "";
136+
try {
137+
138+
res = getTokenPart(token, "id");
139+
} catch (Exception e) {
140+
this.error.setError("JW011", e.getMessage());
141+
return "";
142+
}
143+
return res;
122144
}
123145

124146
/******** EXTERNAL OBJECT PUBLIC METHODS - END ********/
@@ -199,7 +221,7 @@ private boolean doVerify(String token, String expectedAlgorithm, PrivateClaims p
199221

200222
}
201223

202-
private String getTokenPart(String token, String part) {
224+
private String getTokenPart(String token, String part) throws Exception {
203225
DecodedJWT decodedToken = JWT.decode(token);
204226
String base64Part = "";
205227
switch (part) {

0 commit comments

Comments
 (0)