Total Complexity | 5 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | final class AuthTimeChecker implements ClaimChecker |
||
13 | { |
||
14 | private const CLAIM_NAME = 'auth_time'; |
||
15 | |||
16 | /** @var int */ |
||
17 | private $maxAge; |
||
18 | |||
19 | /** @var int */ |
||
20 | private $allowedTimeDrift; |
||
21 | |||
22 | 28 | public function __construct(int $maxAge, int $allowedTimeDrift = 0) |
|
23 | { |
||
24 | 28 | $this->maxAge = $maxAge; |
|
25 | 28 | $this->allowedTimeDrift = $allowedTimeDrift; |
|
26 | 28 | } |
|
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | 14 | public function checkClaim($value): void |
|
32 | { |
||
33 | 14 | if (! is_int($value)) { |
|
34 | 1 | throw new InvalidClaimException('"auth_time" must be an integer.', self::CLAIM_NAME, $value); |
|
35 | } |
||
36 | |||
37 | 13 | if ($value + $this->maxAge < time() - $this->allowedTimeDrift) { |
|
38 | 1 | throw new InvalidClaimException('Too much time has elapsed since the last End-User authentication.', self::CLAIM_NAME, $value); |
|
39 | } |
||
40 | 12 | } |
|
41 | |||
42 | 24 | public function supportedClaim(): string |
|
45 | } |
||
46 | } |
||
47 |