-
Notifications
You must be signed in to change notification settings - Fork 6
/
jws-consume.php
31 lines (27 loc) · 899 Bytes
/
jws-consume.php
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
<?php
/**
* Validate the signature and claims of the JWT token and display claims.
*
* php jws-consume.php $(php jws-create.php)
*/
declare(strict_types = 1);
use Sop\JWX\JWK\Symmetric\SymmetricKeyJWK;
use Sop\JWX\JWT\JWT;
use Sop\JWX\JWT\ValidationContext;
require dirname(__DIR__) . '/vendor/autoload.php';
// read JWT token from the first argument
$jwt = new JWT($argv[1]);
// key to use for signature validation
$jwk = SymmetricKeyJWK::fromKey('secret');
// create validation context
$ctx = ValidationContext::fromJWK($jwk)
->withIssuer('John Doe')
->withSubject('Jane Doe')
->withAudience('acme-client');
// get claims set from the JWT. signature shall be verified and claims
// validated according to validation context.
$claims = $jwt->claims($ctx);
// print all claims
foreach ($claims as $claim) {
printf("%s: %s\n", $claim->name(), json_encode($claim->value()));
}