1010import com .auth0 .jwt .interfaces .DecodedJWT ;
1111import org .apache .commons .codec .binary .Base64 ;
1212
13+ import java .nio .charset .StandardCharsets ;
1314import java .util .*;
1415
1516/**
16- * The JWTVerifier class holds the verify method to assert that a given Token has not only a proper DecodedJWT format, but also it's signature matches.
17+ * The JWTVerifier class holds the verify method to assert that a given Token has not only a proper JWT format, but also it's signature matches.
1718 */
1819@ SuppressWarnings ("WeakerAccess" )
1920public final class JWTVerifier {
@@ -30,7 +31,7 @@ public final class JWTVerifier {
3031 /**
3132 * Initialize a JWTVerifier instance using the given Algorithm.
3233 *
33- * @param algorithm the Algorithm to use on the DecodedJWT verification.
34+ * @param algorithm the Algorithm to use on the JWT verification.
3435 * @return a JWTVerifier.Verification instance to configure.
3536 * @throws IllegalArgumentException if the provided algorithm is null.
3637 */
@@ -39,7 +40,7 @@ static JWTVerifier.Verification init(Algorithm algorithm) throws IllegalArgument
3940 }
4041
4142 /**
42- * The Verification class holds the Claims required by a DecodedJWT to be valid.
43+ * The Verification class holds the Claims required by a JWT to be valid.
4344 */
4445 public static class Verification {
4546 private final Algorithm algorithm ;
@@ -154,7 +155,7 @@ public Verification acceptIssuedAt(long leeway) throws IllegalArgumentException
154155 }
155156
156157 /**
157- * Require a specific DecodedJWT Id ("jti") claim.
158+ * Require a specific JWT Id ("jti") claim.
158159 *
159160 * @param jwtId the required Id value
160161 * @return this same Verification instance.
@@ -232,9 +233,9 @@ private void requireClaim(String name, Object value) {
232233 /**
233234 * Perform the verification against the given Token, using any previous configured options.
234235 *
235- * @param token the String representation of the DecodedJWT .
236- * @return a verified DecodedJWT .
237- * @throws JWTVerificationException if any of the required contents inside the DecodedJWT is invalid.
236+ * @param token to verify .
237+ * @return a verified and decoded JWT .
238+ * @throws JWTVerificationException if any of the required contents inside the JWT is invalid.
238239 */
239240 public DecodedJWT verify (String token ) throws JWTVerificationException {
240241 DecodedJWT jwt = JWTDecoder .decode (token );
@@ -245,14 +246,14 @@ public DecodedJWT verify(String token) throws JWTVerificationException {
245246 }
246247
247248 private void verifySignature (String [] parts ) throws SignatureVerificationException {
248- byte [] content = String .format ("%s.%s" , parts [0 ], parts [1 ]).getBytes ();
249+ byte [] content = String .format ("%s.%s" , parts [0 ], parts [1 ]).getBytes (StandardCharsets . UTF_8 );
249250 byte [] signature = Base64 .decodeBase64 (parts [2 ]);
250251 algorithm .verify (content , signature );
251252 }
252253
253254 private void verifyAlgorithm (DecodedJWT jwt , Algorithm expectedAlgorithm ) throws AlgorithmMismatchException {
254255 if (!expectedAlgorithm .getName ().equals (jwt .getAlgorithm ())) {
255- throw new AlgorithmMismatchException ("The provided Algorithm doesn't match the one defined in the DecodedJWT 's Header." );
256+ throw new AlgorithmMismatchException ("The provided Algorithm doesn't match the one defined in the JWT 's Header." );
256257 }
257258 }
258259
0 commit comments