Completed
Push — master ( d8c018...19ac78 )
by Florent
06:38
created

SubjectChecker::isSubjectAllowed()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
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\Checker;
13
14
use Assert\Assertion;
15
use Jose\Object\JWTInterface;
16
17
abstract class SubjectChecker implements ClaimCheckerInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function checkClaim(JWTInterface $jwt)
23
    {
24
        if (!$jwt->hasClaim('sub')) {
25
            return [];
26
        }
27
28
        $subject = $jwt->getClaim('sub');
29
        Assertion::true($this->isSubjectAllowed($subject), sprintf('The subject "%s" is not allowed.', $subject));
30
31
        return ['sub'];
32
    }
33
34
    /**
35
     * @param string $subject
36
     *
37
     * @return bool
38
     */
39
    abstract protected function isSubjectAllowed($subject);
40
}
41