File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 1212 requires com .google .common ;
1313 requires org .slf4j ;
1414 requires dagger ;
15- requires transitive com .auth0 .jwt ;
15+ requires com .auth0 .jwt ;
1616
1717 // filename-based module required by dagger
1818 // we will probably need to live with this for a while:
Original file line number Diff line number Diff line change @@ -141,22 +141,34 @@ public URI getKeyId() {
141141 return URI .create (unverifiedConfig .getKeyId ());
142142 }
143143
144- public Claim get (String key ) {
145- return unverifiedConfig .getClaim (key );
144+ /**
145+ * Gets a value from the tokens header
146+ * @param key Which key to read
147+ * @param clazz Type of the value
148+ * @param <T> Type of the value
149+ * @return The value or <code>null</code> if the key doesn't exist
150+ */
151+ public <T > T getHeader (String key , Class <T > clazz ) {
152+ var claim = unverifiedConfig .getHeaderClaim (key );
153+ try {
154+ return unverifiedConfig .getHeaderClaim (key ).as (clazz );
155+ } catch (JWTDecodeException e ) {
156+ throw new IllegalArgumentException ("Can't convert " + claim + " to type " + clazz .getName (), e );
157+ }
146158 }
147159
148160 /**
149161 * @return The unverified vault version (signature not verified)
150162 */
151163 public int allegedVaultVersion () {
152- return get (JSON_KEY_VAULTVERSION ).asInt ();
164+ return unverifiedConfig . getClaim (JSON_KEY_VAULTVERSION ).asInt ();
153165 }
154166
155167 /**
156168 * @return The unverified shortening threshold (signature not verified)
157169 */
158170 public int allegedShorteningThreshold () {
159- return get (JSON_KEY_SHORTENING_THRESHOLD ).asInt ();
171+ return unverifiedConfig . getClaim (JSON_KEY_SHORTENING_THRESHOLD ).asInt ();
160172 }
161173
162174 /**
You can’t perform that action at this time.
0 commit comments