Created
January 9, 2022 17:54
-
-
Save raupachz/29d0b91407d22092a4bafb808a465b99 to your computer and use it in GitHub Desktop.
Very basic decoding of a JWT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JWT { | |
private static ObjectMapper objectMapper = new ObjectMapper(); | |
public static Map<String, Object> of(String token) { | |
String[] parts = token.split("\\."); | |
String payload = parts[1]; | |
String json = new String(Base64.getUrlDecoder().decode(payload), StandardCharsets.UTF_8); | |
TypeReference<HashMap<String,Object>> typeRef = new TypeReference<HashMap<String,Object>>() {}; | |
try { | |
return objectMapper.readValue(json, typeRef); | |
} catch (JsonProcessingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment