Passed
Push — master ( 0c0a9d...5256fe )
by Alexandre
01:49
created

IdToken::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: GCC-MED
5
 * Date: 19/01/2018
6
 * Time: 14:30
7
 */
8
9
namespace OAuth2\OpenID\Credentials;
10
11
12
class IdToken
13
{
14
    const DEFINED_CLAIMS = ['iss', 'sub', 'aud', 'exp', 'iat', 'auth_time', 'nonce', 'acr', 'amr', 'azp'];
15
    const REQUIRED_CLAIMS = ['iss', 'sub', 'aud', 'exp', 'iat'];
16
    const STANDARD_CLAIMS = ['sub',
17
        'name', 'given_name', 'family_name', 'middle_name', 'nickname', 'preferred_username',
18
        'profile', 'picture', 'website', 'email', 'email_verified', 'gender', 'birthdate',
19
        'zoneinfo', 'locale', 'phone_number', 'phone_number_verified', 'address', 'update_at'
20
    ];
21
22
    protected $claims = [];
23
24
    /**
25
     * IDToken constructor.
26
     * @param array $claims
27
     * @throws \Exception
28
     */
29
    public function __construct(array $claims)
30
    {
31
        $missingClaims = array_diff(self::REQUIRED_CLAIMS, array_keys($claims));
32
        if (!empty($missingClaims)) {
33
            throw new \Exception('Missing claims : ' . implode(', ', $missingClaims));
34
        }
35
36
        $undefinedClaims = array_diff(array_keys($claims), self::DEFINED_CLAIMS);
37
        if (!empty($undefinedClaims)) {
38
            throw new \Exception('Undefined claims : ' . implode(', ', $undefinedClaims));
39
        }
40
41
        // todo check nonce required if present in authentication request
42
        // todo check auth_time if max_age request is made or auth_time is required via config
43
44
45
        $this->claims = $claims;
46
    }
47
}