1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| <?php
$token = $argv[1] ?? null;
if ($token == '') {
echo "Token empty\n";
exit(1);
}
$parts = explode('.', $token);
echo 'Token has ' . count($parts) . " parts\n";
echo "\n";
echo "Part #0:\n";
$json = base64_decode($parts[0]);
$data = json_decode($json);
if ($data === null) {
echo $json . "\n";
} else {
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
}
echo "\n";
echo "Part #1:\n";
$json = base64_decode($parts[1]);
$data = json_decode($json);
if ($data === null) {
echo $json . "\n";
} else {
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
if (isset($data->iat) && $data->iat !== null) {
echo 'Issued at: ' . date('c', $data->iat) . "\n";
}
if (isset($data->nbf) && $data->nbf !== null) {
echo 'Not before: ' . date('c', $data->nbf) . "\n";
}
if (isset($data->exp) && $data->exp !== null) {
echo 'Expires: ' . date('c', $data->exp) . "\n";
}
}
?>
|