Conditions | 6 |
Paths | 14 |
Total Lines | 33 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
52 | public function __invoke($iat = null, $exp = null) |
||
53 | { |
||
54 | if ($iat === null) { |
||
55 | $iat = time(); |
||
56 | } |
||
57 | |||
58 | if (!is_int($iat)) { |
||
59 | throw new \InvalidArgumentException('iat is not an integer'); |
||
60 | } |
||
61 | |||
62 | if ($exp === null) { |
||
63 | $exp = $iat + $this->ttl; |
||
64 | } |
||
65 | |||
66 | if (!is_int($exp)) { |
||
67 | throw new \InvalidArgumentException('exp is not an integer'); |
||
68 | } |
||
69 | |||
70 | if ($exp < $iat) { |
||
71 | throw new \InvalidArgumentException('exp before iat'); |
||
72 | } |
||
73 | |||
74 | $payload = [ |
||
75 | 'iat' => $iat, |
||
76 | 'ttl' => $exp - $iat, |
||
77 | 'exp' => $exp, |
||
78 | ]; |
||
79 | |||
80 | $payloadBase64 = $this->base64url->encode(json_encode($payload)); |
||
81 | $sign = $this->sign; |
||
82 | |||
83 | return $payloadBase64.'.'.$sign($payloadBase64); |
||
84 | } |
||
85 | } |
||
86 |