@Test public void compact_success() throws Exception { String expectedToken = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJibGFoIn0"; ToBeSignedJwt token = new ToBeSignedJwt.Builder().setJwtId("blah").build(); String compact = token.compact("HS256"); assertThat(compact).isEqualTo(expectedToken); }
String compact(String alg) { JSONObject copy; try { copy = new JSONObject(this.header.toString()); copy.put(JwtNames.HEADER_ALGORITHM, alg); } catch (JSONException ex) { throw new IllegalStateException(ex); } String headerStr = Base64.urlSafeEncode(copy.toString().getBytes(UTF_8)); String payloadStr = Base64.urlSafeEncode(this.payload.toString().getBytes(UTF_8)); return headerStr + "." + payloadStr; }
ToBeSignedJwt { String compact(String alg) { JSONObject copy; try { copy = new JSONObject(this.header.toString()); copy.put(JwtNames.HEADER_ALGORITHM, alg); } catch (JSONException ex) { throw new IllegalStateException(ex); } String headerStr = Base64.urlSafeEncode(copy.toString().getBytes(UTF_8)); String payloadStr = Base64.urlSafeEncode(this.payload.toString().getBytes(UTF_8)); return headerStr + "." + payloadStr; } }
ToBeSignedJwt { String compact(String alg) { JSONObject copy; try { copy = new JSONObject(this.header.toString()); copy.put(JwtNames.HEADER_ALGORITHM, alg); } catch (JSONException ex) { throw new IllegalStateException(ex); } String headerStr = Base64.urlSafeEncode(copy.toString().getBytes(UTF_8)); String payloadStr = Base64.urlSafeEncode(this.payload.toString().getBytes(UTF_8)); return headerStr + "." + payloadStr; } private  ToBeSignedJwt(Builder builder); }
ToBeSignedJwt { String compact(String alg) { JSONObject copy; try { copy = new JSONObject(this.header.toString()); copy.put(JwtNames.HEADER_ALGORITHM, alg); } catch (JSONException ex) { throw new IllegalStateException(ex); } String headerStr = Base64.urlSafeEncode(copy.toString().getBytes(UTF_8)); String payloadStr = Base64.urlSafeEncode(this.payload.toString().getBytes(UTF_8)); return headerStr + "." + payloadStr; } private  ToBeSignedJwt(Builder builder);  }
ToBeSignedJwt { String compact(String alg) { JSONObject copy; try { copy = new JSONObject(this.header.toString()); copy.put(JwtNames.HEADER_ALGORITHM, alg); } catch (JSONException ex) { throw new IllegalStateException(ex); } String headerStr = Base64.urlSafeEncode(copy.toString().getBytes(UTF_8)); String payloadStr = Base64.urlSafeEncode(this.payload.toString().getBytes(UTF_8)); return headerStr + "." + payloadStr; } private  ToBeSignedJwt(Builder builder);   }