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
|
|
|
} |