...
Code Block | ||||
---|---|---|---|---|
| ||||
import java.util.Base64; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonReader; import java.io.StringReader; public class ParseJWT { public voidString parseClientId(String token) { // Split token into its parts String[] chunks = token.split("\\."); Base64.Decoder decoder = Base64.getUrlDecoder(); // Decode payload String payload = new String(decoder.decode(chunks[1])); // Parse JSON JsonReader jsonReader = Json.createReader(new StringReader(payload)); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close(); // Extract the client_id String clientId = jsonObject.getString("client_id"); System.out.println("Client ID: " + clientId); return clientId; } } |
...