1 | <?php |
||
29 | class JsonWebToken |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $key; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $algorithm = 'HS256'; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $claims = array(); |
||
45 | |||
46 | /** |
||
47 | * JsonWebToken constructor. |
||
48 | * |
||
49 | * @param string $key key for signing/validating |
||
50 | * @param string $algorithm algorithm to use for signing/validating |
||
51 | */ |
||
52 | 1 | public function __construct($key = null, $algorithm = 'HS256') |
|
61 | |||
62 | /** |
||
63 | * Set the key |
||
64 | * |
||
65 | * @param string $key key for signing/validating |
||
66 | * |
||
67 | * @return JsonWebToken |
||
68 | */ |
||
69 | 1 | public function setKey($key) |
|
74 | |||
75 | /** |
||
76 | * @param string $algorithm algorithm to use for signing/validating |
||
77 | * |
||
78 | * @return JsonWebToken |
||
79 | * |
||
80 | * @throws \DomainException |
||
81 | */ |
||
82 | 1 | public function setAlgorithm($algorithm) |
|
90 | |||
91 | /** |
||
92 | * Decode a JWT string, validating signature and well defined registered claims, |
||
93 | * and optionally validate against a list of supplied claims |
||
94 | * |
||
95 | * @param string $jwtString string containing the JWT to decode |
||
96 | * @param array $assertClaims associative array, claim => value, of claims to assert |
||
97 | * |
||
98 | * @return object|false |
||
99 | */ |
||
100 | 1 | public function decode($jwtString, $assertClaims = array()) |
|
118 | |||
119 | /** |
||
120 | * @param array $payload associative array og claims, claim => value |
||
121 | * @param int $expirationOffset seconds from now that token will expire. If not specified, |
||
122 | * an "exp" claim will not be added or updated |
||
123 | * |
||
124 | * @return string encoded and signed jwt string |
||
125 | * |
||
126 | * @throws \DomainException; |
||
127 | * @throws \InvalidArgumentException; |
||
128 | * @throws \UnexpectedValueException; |
||
129 | */ |
||
130 | 1 | public function create($payload, $expirationOffset = 0) |
|
138 | } |
||
139 |