MCPcopy Index your code
hub / github.com/auth0/java-jwt / JWTDecoder

Class JWTDecoder

lib/src/main/java/com/auth0/jwt/JWTDecoder.java:23–156  ·  view source on GitHub ↗

The JWTDecoder class holds the decode method to parse a given JWT token into it's JWT representation. This class is thread-safe.

Source from the content-addressed store, hash-verified

21 * This class is thread-safe.
22 */
23@SuppressWarnings("WeakerAccess")
24final class JWTDecoder implements DecodedJWT, Serializable {
25
26 private static final long serialVersionUID = 1873362438023312895L;
27
28 private final String[] parts;
29 private final Header header;
30 private final Payload payload;
31
32 JWTDecoder(String jwt) throws JWTDecodeException {
33 this(new JWTParser(), jwt);
34 }
35
36 JWTDecoder(JWTParser converter, String jwt) throws JWTDecodeException {
37 parts = TokenUtils.splitToken(jwt);
38 String headerJson;
39 String payloadJson;
40 try {
41 headerJson = new String(Base64.getUrlDecoder().decode(parts[0]), StandardCharsets.UTF_8);
42 payloadJson = new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
43 } catch (NullPointerException e) {
44 throw new JWTDecodeException("The UTF-8 Charset isn't initialized.", e);
45 } catch (IllegalArgumentException e) {
46 throw new JWTDecodeException("The input is not a valid base 64 encoded string.", e);
47 }
48 header = converter.parseHeader(headerJson);
49 payload = converter.parsePayload(payloadJson);
50 }
51
52 @Override
53 public String getAlgorithm() {
54 return header.getAlgorithm();
55 }
56
57 @Override
58 public String getType() {
59 return header.getType();
60 }
61
62 @Override
63 public String getContentType() {
64 return header.getContentType();
65 }
66
67 @Override
68 public String getKeyId() {
69 return header.getKeyId();
70 }
71
72 @Override
73 public Claim getHeaderClaim(String name) {
74 return header.getHeaderClaim(name);
75 }
76
77 @Override
78 public String getIssuer() {
79 return payload.getIssuer();
80 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…