@@ -54,14 +54,28 @@ public class JWTUtil {
5454
5555 public static Pair <String , String > createJWT (String typ , String alg , String userInput ,
5656 String iss , String sub , String aud , boolean iat , long exp ) {
57-
5857 /* Construct JWT Header */
5958 Map <String , Object > header = new TreeMap <>();
6059 header .put ("alg" , Objects .requireNonNullElse (alg , "HS256" ));
6160 header .put ("typ" , Objects .requireNonNullElse (typ , "JWT" ));
6261 log .debug (header .toString ());
6362
6463 /* Construct JWT Payload */
64+ JSONObject payload = createPayload (userInput , iss , sub , aud , iat , exp );
65+
66+ Key key = signingKey (alg );
67+
68+ JwtBuilder jwtBuilder = Jwts .builder ()
69+ .setHeader (header )
70+ .setPayload (payload .toString ())
71+ .signWith (key );
72+
73+ String jws = jwtBuilder .compact ();
74+
75+ return new Pair <>(jws , Encoders .BASE64 .encode (key .getEncoded ()));
76+ }
77+
78+ private static JSONObject createPayload (String userInput , String iss , String sub , String aud , boolean iat , long exp ) {
6579 JSONObject payload = new JSONObject (userInput );
6680 if (iss != null ) {
6781 payload .put ("iss" , iss );
@@ -78,20 +92,9 @@ public static Pair<String, String> createJWT(String typ, String alg, String user
7892 }
7993
8094 if (exp != 0 ) {
81- // Converting milliseconds to nanoseconds
82- payload .put ("exp" , System .nanoTime () + exp * 1000 * 1000 );
95+ payload .put ("exp" , System .nanoTime () + exp * 1000 * 1000 ); // Converting milliseconds to nanoseconds
8396 }
84-
85- Key key = signingKey (alg );
86-
87- JwtBuilder jwtBuilder = Jwts .builder ()
88- .setHeader (header )
89- .setPayload (payload .toString ())
90- .signWith (key );
91-
92- String jws = jwtBuilder .compact ();
93-
94- return new Pair <>(jws , Encoders .BASE64 .encode (key .getEncoded ()));
97+ return payload ;
9598 }
9699
97100 public static Key signingKey (String algorithm ) {
0 commit comments