Completed
Push — master ( a94a5c...e317aa )
by Florent
02:24
created

JtiChecker::isJtiValid()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 1
nc 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\ClaimChecker;
13
14
use Jose\Object\JWTInterface;
15
16
abstract class JtiChecker implements ClaimCheckerInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function checkClaim(JWTInterface $jwt)
22
    {
23
        if (!$jwt->hasClaim('jti')) {
24
            return [];
25
        }
26
27
        $jti = $jwt->getClaim('jti');
28
        if (!$this->isJtiValid($jti)) {
29
            throw new \InvalidArgumentException(sprintf('Invalid token ID "%s".', $jti));
30
        }
31
32
        return ['jti'];
33
    }
34
35
    /**
36
     * @param string $jti
37
     *
38
     * @return bool
39
     */
40
    abstract protected function isJtiValid($jti);
41
}
42