@@ -11,84 +11,84 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class RegisteredClaim extends Claim |
13 | 13 | { |
14 | - // JWT claims |
|
15 | - const NAME_ISSUER = 'iss'; |
|
16 | - const NAME_SUBJECT = 'sub'; |
|
17 | - const NAME_AUDIENCE = 'aud'; |
|
18 | - const NAME_EXPIRATION_TIME = 'exp'; |
|
19 | - const NAME_NOT_BEFORE = 'nbf'; |
|
20 | - const NAME_ISSUED_AT = 'iat'; |
|
21 | - const NAME_JWT_ID = 'jti'; |
|
14 | + // JWT claims |
|
15 | + const NAME_ISSUER = 'iss'; |
|
16 | + const NAME_SUBJECT = 'sub'; |
|
17 | + const NAME_AUDIENCE = 'aud'; |
|
18 | + const NAME_EXPIRATION_TIME = 'exp'; |
|
19 | + const NAME_NOT_BEFORE = 'nbf'; |
|
20 | + const NAME_ISSUED_AT = 'iat'; |
|
21 | + const NAME_JWT_ID = 'jti'; |
|
22 | 22 | |
23 | - // OpenID claims |
|
24 | - const NAME_FULL_NAME = 'name'; |
|
25 | - const NAME_GIVEN_NAME = 'given_name'; |
|
26 | - const NAME_FAMILY_NAME = 'family_name'; |
|
27 | - const NAME_MIDDLE_NAME = 'middle_name'; |
|
28 | - const NAME_NICKNAME = 'nickname'; |
|
29 | - const NAME_PREFERRED_USERNAME = 'preferred_username'; |
|
30 | - const NAME_PROFILE_URL = 'profile'; |
|
31 | - const NAME_PICTURE_URL = 'picture'; |
|
32 | - const NAME_WEBSITE_URL = 'website'; |
|
33 | - const NAME_EMAIL = 'email'; |
|
34 | - const NAME_EMAIL_VERIFIED = 'email_verified'; |
|
35 | - const NAME_GENDER = 'gender'; |
|
36 | - const NAME_BIRTHDATE = 'birthdate'; |
|
37 | - const NAME_TIMEZONE = 'zoneinfo'; |
|
38 | - const NAME_LOCALE = 'locale'; |
|
39 | - const NAME_PHONE_NUMBER = 'phone_number'; |
|
40 | - const NAME_PHONE_NUMBER_VERIFIED = 'phone_number_verified'; |
|
41 | - const NAME_ADDRESS = 'address'; |
|
42 | - const NAME_UPDATED_AT = 'updated_at'; |
|
43 | - const NAME_AUTHORIZED_PARTY = 'azp'; |
|
44 | - const NAME_NONCE = 'nonce'; |
|
45 | - const NAME_AUTH_TIME = 'auth_time'; |
|
46 | - const NAME_ACCESS_TOKEN_HASH = 'at_hash'; |
|
47 | - const NAME_CODE_HASH = 'c_hash'; |
|
48 | - const NAME_ACR = 'acr'; |
|
49 | - const NAME_AMR = 'amr'; |
|
50 | - const NAME_SUB_JWK = 'sub_jwk'; |
|
23 | + // OpenID claims |
|
24 | + const NAME_FULL_NAME = 'name'; |
|
25 | + const NAME_GIVEN_NAME = 'given_name'; |
|
26 | + const NAME_FAMILY_NAME = 'family_name'; |
|
27 | + const NAME_MIDDLE_NAME = 'middle_name'; |
|
28 | + const NAME_NICKNAME = 'nickname'; |
|
29 | + const NAME_PREFERRED_USERNAME = 'preferred_username'; |
|
30 | + const NAME_PROFILE_URL = 'profile'; |
|
31 | + const NAME_PICTURE_URL = 'picture'; |
|
32 | + const NAME_WEBSITE_URL = 'website'; |
|
33 | + const NAME_EMAIL = 'email'; |
|
34 | + const NAME_EMAIL_VERIFIED = 'email_verified'; |
|
35 | + const NAME_GENDER = 'gender'; |
|
36 | + const NAME_BIRTHDATE = 'birthdate'; |
|
37 | + const NAME_TIMEZONE = 'zoneinfo'; |
|
38 | + const NAME_LOCALE = 'locale'; |
|
39 | + const NAME_PHONE_NUMBER = 'phone_number'; |
|
40 | + const NAME_PHONE_NUMBER_VERIFIED = 'phone_number_verified'; |
|
41 | + const NAME_ADDRESS = 'address'; |
|
42 | + const NAME_UPDATED_AT = 'updated_at'; |
|
43 | + const NAME_AUTHORIZED_PARTY = 'azp'; |
|
44 | + const NAME_NONCE = 'nonce'; |
|
45 | + const NAME_AUTH_TIME = 'auth_time'; |
|
46 | + const NAME_ACCESS_TOKEN_HASH = 'at_hash'; |
|
47 | + const NAME_CODE_HASH = 'c_hash'; |
|
48 | + const NAME_ACR = 'acr'; |
|
49 | + const NAME_AMR = 'amr'; |
|
50 | + const NAME_SUB_JWK = 'sub_jwk'; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Mapping from registered claim name to class name. |
|
54 | - * |
|
55 | - * @internal |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - const MAP_NAME_TO_CLASS = [ |
|
60 | - self::NAME_ISSUER => IssuerClaim::class, |
|
61 | - self::NAME_SUBJECT => SubjectClaim::class, |
|
62 | - self::NAME_AUDIENCE => AudienceClaim::class, |
|
63 | - self::NAME_EXPIRATION_TIME => ExpirationTimeClaim::class, |
|
64 | - self::NAME_NOT_BEFORE => NotBeforeClaim::class, |
|
65 | - self::NAME_ISSUED_AT => IssuedAtClaim::class, |
|
66 | - self::NAME_JWT_ID => JWTIDClaim::class, |
|
67 | - ]; |
|
52 | + /** |
|
53 | + * Mapping from registered claim name to class name. |
|
54 | + * |
|
55 | + * @internal |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + const MAP_NAME_TO_CLASS = [ |
|
60 | + self::NAME_ISSUER => IssuerClaim::class, |
|
61 | + self::NAME_SUBJECT => SubjectClaim::class, |
|
62 | + self::NAME_AUDIENCE => AudienceClaim::class, |
|
63 | + self::NAME_EXPIRATION_TIME => ExpirationTimeClaim::class, |
|
64 | + self::NAME_NOT_BEFORE => NotBeforeClaim::class, |
|
65 | + self::NAME_ISSUED_AT => IssuedAtClaim::class, |
|
66 | + self::NAME_JWT_ID => JWTIDClaim::class, |
|
67 | + ]; |
|
68 | 68 | |
69 | - /** |
|
70 | - * Constructor. |
|
71 | - * |
|
72 | - * Defined here for type strictness. Parameters are passed to the |
|
73 | - * superclass. |
|
74 | - * |
|
75 | - * @param mixed ...$args |
|
76 | - */ |
|
77 | - public function __construct(...$args) |
|
78 | - { |
|
79 | - parent::__construct((string) $args[0], $args[1], |
|
80 | - isset($args[2]) ? $args[2] : null); |
|
81 | - } |
|
69 | + /** |
|
70 | + * Constructor. |
|
71 | + * |
|
72 | + * Defined here for type strictness. Parameters are passed to the |
|
73 | + * superclass. |
|
74 | + * |
|
75 | + * @param mixed ...$args |
|
76 | + */ |
|
77 | + public function __construct(...$args) |
|
78 | + { |
|
79 | + parent::__construct((string) $args[0], $args[1], |
|
80 | + isset($args[2]) ? $args[2] : null); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Initialize concrete claim instance from a JSON value. |
|
85 | - * |
|
86 | - * @param mixed $value |
|
87 | - * |
|
88 | - * @return RegisteredClaim |
|
89 | - */ |
|
90 | - public static function fromJSONValue($value): RegisteredClaim |
|
91 | - { |
|
92 | - return new static($value); |
|
93 | - } |
|
83 | + /** |
|
84 | + * Initialize concrete claim instance from a JSON value. |
|
85 | + * |
|
86 | + * @param mixed $value |
|
87 | + * |
|
88 | + * @return RegisteredClaim |
|
89 | + */ |
|
90 | + public static function fromJSONValue($value): RegisteredClaim |
|
91 | + { |
|
92 | + return new static($value); |
|
93 | + } |
|
94 | 94 | } |
@@ -15,18 +15,18 @@ |
||
15 | 15 | */ |
16 | 16 | class ExpirationTimeClaim extends RegisteredClaim |
17 | 17 | { |
18 | - use NumericDateClaim; |
|
19 | - use ReferenceTimeValidation; |
|
18 | + use NumericDateClaim; |
|
19 | + use ReferenceTimeValidation; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @param int $exp_time Expiration time as a unix timestamp |
|
25 | - */ |
|
26 | - public function __construct(int $exp_time) |
|
27 | - { |
|
28 | - // validate that claim is after the constraint (reference time) |
|
29 | - parent::__construct(self::NAME_EXPIRATION_TIME, $exp_time, |
|
30 | - new GreaterValidator()); |
|
31 | - } |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @param int $exp_time Expiration time as a unix timestamp |
|
25 | + */ |
|
26 | + public function __construct(int $exp_time) |
|
27 | + { |
|
28 | + // validate that claim is after the constraint (reference time) |
|
29 | + parent::__construct(self::NAME_EXPIRATION_TIME, $exp_time, |
|
30 | + new GreaterValidator()); |
|
31 | + } |
|
32 | 32 | } |
@@ -11,39 +11,39 @@ |
||
11 | 11 | */ |
12 | 12 | trait ReferenceTimeValidation |
13 | 13 | { |
14 | - /** |
|
15 | - * Validate the claim against given constraint. |
|
16 | - * |
|
17 | - * @param mixed $constraint |
|
18 | - * |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - abstract public function validate($constraint): bool; |
|
14 | + /** |
|
15 | + * Validate the claim against given constraint. |
|
16 | + * |
|
17 | + * @param mixed $constraint |
|
18 | + * |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + abstract public function validate($constraint): bool; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Override default Claim validation. |
|
25 | - * |
|
26 | - * Uses reference time of the validation context as a constraint. |
|
27 | - * |
|
28 | - * @see \Sop\JWX\JWT\Claim\Claim::validateWithContext() |
|
29 | - * |
|
30 | - * @param ValidationContext $ctx |
|
31 | - * |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function validateWithContext(ValidationContext $ctx): bool |
|
35 | - { |
|
36 | - if ($ctx->hasReferenceTime()) { |
|
37 | - // try to validate with leeway added |
|
38 | - if ($this->validate($ctx->referenceTime() + $ctx->leeway())) { |
|
39 | - return true; |
|
40 | - } |
|
41 | - // try to validate with leeway substracted |
|
42 | - if ($this->validate($ctx->referenceTime() - $ctx->leeway())) { |
|
43 | - return true; |
|
44 | - } |
|
45 | - return false; |
|
46 | - } |
|
47 | - return true; |
|
48 | - } |
|
23 | + /** |
|
24 | + * Override default Claim validation. |
|
25 | + * |
|
26 | + * Uses reference time of the validation context as a constraint. |
|
27 | + * |
|
28 | + * @see \Sop\JWX\JWT\Claim\Claim::validateWithContext() |
|
29 | + * |
|
30 | + * @param ValidationContext $ctx |
|
31 | + * |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function validateWithContext(ValidationContext $ctx): bool |
|
35 | + { |
|
36 | + if ($ctx->hasReferenceTime()) { |
|
37 | + // try to validate with leeway added |
|
38 | + if ($this->validate($ctx->referenceTime() + $ctx->leeway())) { |
|
39 | + return true; |
|
40 | + } |
|
41 | + // try to validate with leeway substracted |
|
42 | + if ($this->validate($ctx->referenceTime() - $ctx->leeway())) { |
|
43 | + return true; |
|
44 | + } |
|
45 | + return false; |
|
46 | + } |
|
47 | + return true; |
|
48 | + } |
|
49 | 49 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | */ |
14 | 14 | class IssuerClaim extends RegisteredClaim |
15 | 15 | { |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $issuer |
|
20 | - */ |
|
21 | - public function __construct(string $issuer) |
|
22 | - { |
|
23 | - parent::__construct(self::NAME_ISSUER, $issuer, new EqualsValidator()); |
|
24 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $issuer |
|
20 | + */ |
|
21 | + public function __construct(string $issuer) |
|
22 | + { |
|
23 | + parent::__construct(self::NAME_ISSUER, $issuer, new EqualsValidator()); |
|
24 | + } |
|
25 | 25 | } |
@@ -9,11 +9,11 @@ |
||
9 | 9 | */ |
10 | 10 | class EqualsValidator extends Validator |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - public function validate($value, $constraint): bool |
|
16 | - { |
|
17 | - return $value == $constraint; |
|
18 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + public function validate($value, $constraint): bool |
|
16 | + { |
|
17 | + return $value == $constraint; |
|
18 | + } |
|
19 | 19 | } |
@@ -12,14 +12,14 @@ |
||
12 | 12 | */ |
13 | 13 | class ContainsValidator extends Validator |
14 | 14 | { |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public function validate($value, $constraint): bool |
|
19 | - { |
|
20 | - if (is_array($value)) { |
|
21 | - return in_array($constraint, $value); |
|
22 | - } |
|
23 | - return $value == $constraint; |
|
24 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public function validate($value, $constraint): bool |
|
19 | + { |
|
20 | + if (is_array($value)) { |
|
21 | + return in_array($constraint, $value); |
|
22 | + } |
|
23 | + return $value == $constraint; |
|
24 | + } |
|
25 | 25 | } |
@@ -9,11 +9,11 @@ |
||
9 | 9 | */ |
10 | 10 | class GreaterValidator extends Validator |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - public function validate($value, $constraint): bool |
|
16 | - { |
|
17 | - return $value > $constraint; |
|
18 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + public function validate($value, $constraint): bool |
|
16 | + { |
|
17 | + return $value > $constraint; |
|
18 | + } |
|
19 | 19 | } |
@@ -9,11 +9,11 @@ |
||
9 | 9 | */ |
10 | 10 | class LessValidator extends Validator |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - public function validate($value, $constraint): bool |
|
16 | - { |
|
17 | - return $value < $constraint; |
|
18 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + public function validate($value, $constraint): bool |
|
16 | + { |
|
17 | + return $value < $constraint; |
|
18 | + } |
|
19 | 19 | } |
@@ -10,11 +10,11 @@ |
||
10 | 10 | */ |
11 | 11 | class GreaterOrEqualValidator extends Validator |
12 | 12 | { |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function validate($value, $constraint): bool |
|
17 | - { |
|
18 | - return $value >= $constraint; |
|
19 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function validate($value, $constraint): bool |
|
17 | + { |
|
18 | + return $value >= $constraint; |
|
19 | + } |
|
20 | 20 | } |