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

AudienceChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
class AudienceChecker implements ClaimCheckerInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    private $audience;
22
23
    /**
24
     * AudienceChecker constructor.
25
     *
26
     * @param string $audience
27
     */
28
    public function __construct($audience)
29
    {
30
        $this->audience = $audience;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function checkClaim(JWTInterface $jwt)
37
    {
38
        if (!$jwt->hasClaim('aud')) {
39
            return [];
40
        }
41
42
        $audience = $jwt->getClaim('aud');
43
        if ($audience !== $this->getAudience()) {
44
            throw new \InvalidArgumentException('Bad audience.');
45
        }
46
47
        return ['aud'];
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getAudience()
54
    {
55
        return $this->audience;
56
    }
57
}
58