Jwt { public List<String> getAudiences() throws JwtExpiredException, JwtNotBeforeException { JSONArray audiences = (JSONArray) getClaim(JwtNames.CLAIM_AUDIENCE); if (audiences == null) { return null; } List<String> result = new ArrayList<>(audiences.length()); for (int i = 0; i < audiences.length(); i++) { try { result.add(audiences.getString(i)); } catch (JSONException ex) { throw new IllegalStateException("invalid audience", ex); } } return Collections.unmodifiableList(result); } Jwt(JSONObject header, JSONObject payload, Clock clock, Duration clockSkew); String getIssuer(); String getSubject(); List<String> getAudiences(); String getJwtId(); Instant getExpiration(); Instant getNotBefore(); Instant getIssuedAt(); Object getClaim(String name); String getType(); String getContentType(); String getAlgorithm(); String getKeyId();  }
@Test public void getAudiences_success() throws Exception { JSONObject payload = new JSONObject(); JSONArray audiences = new JSONArray(); audiences.put("foo"); payload.put(JwtNames.CLAIM_AUDIENCE, audiences); Jwt token = new Jwt(new JSONObject(), payload, Clock.systemUTC(), Duration.ZERO); assertThat(token.getAudiences()).containsExactly("foo"); }
@Test public void getMultipleAudiences_success() throws Exception { JSONObject payload = new JSONObject(); JSONArray audiences = new JSONArray(); audiences.put("foo"); audiences.put("bar"); payload.put(JwtNames.CLAIM_AUDIENCE, audiences); Jwt token = new Jwt(new JSONObject(), payload, Clock.systemUTC(), Duration.ZERO); assertThat(token.getAudiences()).containsExactly("foo", "bar"); }