@@ -11,153 +11,153 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Header implements \Countable, \IteratorAggregate |
| 13 | 13 | { |
| 14 | - use TypedHeader; |
|
| 14 | + use TypedHeader; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Parameters. |
|
| 18 | - * |
|
| 19 | - * @var JWTParameter[] $_parameters |
|
| 20 | - */ |
|
| 21 | - protected $_parameters; |
|
| 16 | + /** |
|
| 17 | + * Parameters. |
|
| 18 | + * |
|
| 19 | + * @var JWTParameter[] $_parameters |
|
| 20 | + */ |
|
| 21 | + protected $_parameters; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param JWTParameter ...$params Parameters |
|
| 27 | - */ |
|
| 28 | - public function __construct(JWTParameter ...$params) |
|
| 29 | - { |
|
| 30 | - $this->_parameters = array(); |
|
| 31 | - foreach ($params as $param) { |
|
| 32 | - $this->_parameters[$param->name()] = $param; |
|
| 33 | - } |
|
| 34 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param JWTParameter ...$params Parameters |
|
| 27 | + */ |
|
| 28 | + public function __construct(JWTParameter ...$params) |
|
| 29 | + { |
|
| 30 | + $this->_parameters = array(); |
|
| 31 | + foreach ($params as $param) { |
|
| 32 | + $this->_parameters[$param->name()] = $param; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Initialize from an array representing a JSON object. |
|
| 38 | - * |
|
| 39 | - * @param array $members |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromArray(array $members): self |
|
| 43 | - { |
|
| 44 | - $params = array(); |
|
| 45 | - foreach ($members as $name => $value) { |
|
| 46 | - $params[] = JWTParameter::fromNameAndValue($name, $value); |
|
| 47 | - } |
|
| 48 | - return new self(...$params); |
|
| 49 | - } |
|
| 36 | + /** |
|
| 37 | + * Initialize from an array representing a JSON object. |
|
| 38 | + * |
|
| 39 | + * @param array $members |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromArray(array $members): self |
|
| 43 | + { |
|
| 44 | + $params = array(); |
|
| 45 | + foreach ($members as $name => $value) { |
|
| 46 | + $params[] = JWTParameter::fromNameAndValue($name, $value); |
|
| 47 | + } |
|
| 48 | + return new self(...$params); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Initialize from a JSON. |
|
| 53 | - * |
|
| 54 | - * @param string $json |
|
| 55 | - * @throws \UnexpectedValueException |
|
| 56 | - * @return self |
|
| 57 | - */ |
|
| 58 | - public static function fromJSON(string $json): self |
|
| 59 | - { |
|
| 60 | - $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING); |
|
| 61 | - if (!is_array($members)) { |
|
| 62 | - throw new \UnexpectedValueException("Invalid JSON."); |
|
| 63 | - } |
|
| 64 | - return self::fromArray($members); |
|
| 65 | - } |
|
| 51 | + /** |
|
| 52 | + * Initialize from a JSON. |
|
| 53 | + * |
|
| 54 | + * @param string $json |
|
| 55 | + * @throws \UnexpectedValueException |
|
| 56 | + * @return self |
|
| 57 | + */ |
|
| 58 | + public static function fromJSON(string $json): self |
|
| 59 | + { |
|
| 60 | + $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING); |
|
| 61 | + if (!is_array($members)) { |
|
| 62 | + throw new \UnexpectedValueException("Invalid JSON."); |
|
| 63 | + } |
|
| 64 | + return self::fromArray($members); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get self with parameters added. |
|
| 69 | - * |
|
| 70 | - * @param JWTParameter ...$param |
|
| 71 | - * @return self |
|
| 72 | - */ |
|
| 73 | - public function withParameters(JWTParameter ...$params): self |
|
| 74 | - { |
|
| 75 | - $obj = clone $this; |
|
| 76 | - foreach ($params as $param) { |
|
| 77 | - $obj->_parameters[$param->name()] = $param; |
|
| 78 | - } |
|
| 79 | - return $obj; |
|
| 80 | - } |
|
| 67 | + /** |
|
| 68 | + * Get self with parameters added. |
|
| 69 | + * |
|
| 70 | + * @param JWTParameter ...$param |
|
| 71 | + * @return self |
|
| 72 | + */ |
|
| 73 | + public function withParameters(JWTParameter ...$params): self |
|
| 74 | + { |
|
| 75 | + $obj = clone $this; |
|
| 76 | + foreach ($params as $param) { |
|
| 77 | + $obj->_parameters[$param->name()] = $param; |
|
| 78 | + } |
|
| 79 | + return $obj; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Get all parameters. |
|
| 84 | - * |
|
| 85 | - * @return JWTParameter[] |
|
| 86 | - */ |
|
| 87 | - public function parameters(): array |
|
| 88 | - { |
|
| 89 | - return $this->_parameters; |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Get all parameters. |
|
| 84 | + * |
|
| 85 | + * @return JWTParameter[] |
|
| 86 | + */ |
|
| 87 | + public function parameters(): array |
|
| 88 | + { |
|
| 89 | + return $this->_parameters; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Whether parameters are present. |
|
| 94 | - * |
|
| 95 | - * Returns false if any of the given parameters is not set. |
|
| 96 | - * |
|
| 97 | - * @param string ...$names Parameter names |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - public function has(string ...$names): bool |
|
| 101 | - { |
|
| 102 | - foreach ($names as $name) { |
|
| 103 | - if (!isset($this->_parameters[$name])) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - return true; |
|
| 108 | - } |
|
| 92 | + /** |
|
| 93 | + * Whether parameters are present. |
|
| 94 | + * |
|
| 95 | + * Returns false if any of the given parameters is not set. |
|
| 96 | + * |
|
| 97 | + * @param string ...$names Parameter names |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + public function has(string ...$names): bool |
|
| 101 | + { |
|
| 102 | + foreach ($names as $name) { |
|
| 103 | + if (!isset($this->_parameters[$name])) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Get a parameter. |
|
| 112 | - * |
|
| 113 | - * @param string $name Parameter name |
|
| 114 | - * @throws \LogicException |
|
| 115 | - * @return JWTParameter |
|
| 116 | - */ |
|
| 117 | - public function get(string $name): JWTParameter |
|
| 118 | - { |
|
| 119 | - if (!$this->has($name)) { |
|
| 120 | - throw new \LogicException("Parameter $name doesn't exists."); |
|
| 121 | - } |
|
| 122 | - return $this->_parameters[$name]; |
|
| 123 | - } |
|
| 110 | + /** |
|
| 111 | + * Get a parameter. |
|
| 112 | + * |
|
| 113 | + * @param string $name Parameter name |
|
| 114 | + * @throws \LogicException |
|
| 115 | + * @return JWTParameter |
|
| 116 | + */ |
|
| 117 | + public function get(string $name): JWTParameter |
|
| 118 | + { |
|
| 119 | + if (!$this->has($name)) { |
|
| 120 | + throw new \LogicException("Parameter $name doesn't exists."); |
|
| 121 | + } |
|
| 122 | + return $this->_parameters[$name]; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Convert to a JSON. |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function toJSON(): string |
|
| 131 | - { |
|
| 132 | - if (empty($this->_parameters)) { |
|
| 133 | - return ""; |
|
| 134 | - } |
|
| 135 | - $data = array(); |
|
| 136 | - foreach ($this->_parameters as $param) { |
|
| 137 | - $data[$param->name()] = $param->value(); |
|
| 138 | - } |
|
| 139 | - return json_encode((object) $data, JSON_UNESCAPED_SLASHES); |
|
| 140 | - } |
|
| 125 | + /** |
|
| 126 | + * Convert to a JSON. |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function toJSON(): string |
|
| 131 | + { |
|
| 132 | + if (empty($this->_parameters)) { |
|
| 133 | + return ""; |
|
| 134 | + } |
|
| 135 | + $data = array(); |
|
| 136 | + foreach ($this->_parameters as $param) { |
|
| 137 | + $data[$param->name()] = $param->value(); |
|
| 138 | + } |
|
| 139 | + return json_encode((object) $data, JSON_UNESCAPED_SLASHES); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get the number of parameters. |
|
| 144 | - * |
|
| 145 | - * @see \Countable::count() |
|
| 146 | - * @return int |
|
| 147 | - */ |
|
| 148 | - public function count(): int |
|
| 149 | - { |
|
| 150 | - return count($this->_parameters); |
|
| 151 | - } |
|
| 142 | + /** |
|
| 143 | + * Get the number of parameters. |
|
| 144 | + * |
|
| 145 | + * @see \Countable::count() |
|
| 146 | + * @return int |
|
| 147 | + */ |
|
| 148 | + public function count(): int |
|
| 149 | + { |
|
| 150 | + return count($this->_parameters); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Get iterator for the parameters. |
|
| 155 | - * |
|
| 156 | - * @see \IteratorAggregate::getIterator() |
|
| 157 | - * @return \ArrayIterator |
|
| 158 | - */ |
|
| 159 | - public function getIterator(): \ArrayIterator |
|
| 160 | - { |
|
| 161 | - return new \ArrayIterator($this->_parameters); |
|
| 162 | - } |
|
| 153 | + /** |
|
| 154 | + * Get iterator for the parameters. |
|
| 155 | + * |
|
| 156 | + * @see \IteratorAggregate::getIterator() |
|
| 157 | + * @return \ArrayIterator |
|
| 158 | + */ |
|
| 159 | + public function getIterator(): \ArrayIterator |
|
| 160 | + { |
|
| 161 | + return new \ArrayIterator($this->_parameters); |
|
| 162 | + } |
|
| 163 | 163 | } |
@@ -26,308 +26,308 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class ValidationContext |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * Reference time. |
|
| 31 | - * |
|
| 32 | - * @var int $_refTime |
|
| 33 | - */ |
|
| 34 | - protected $_refTime; |
|
| 29 | + /** |
|
| 30 | + * Reference time. |
|
| 31 | + * |
|
| 32 | + * @var int $_refTime |
|
| 33 | + */ |
|
| 34 | + protected $_refTime; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Leeway in seconds for the reference time constraints. |
|
| 38 | - * |
|
| 39 | - * @var int $_leeway |
|
| 40 | - */ |
|
| 41 | - protected $_leeway; |
|
| 36 | + /** |
|
| 37 | + * Leeway in seconds for the reference time constraints. |
|
| 38 | + * |
|
| 39 | + * @var int $_leeway |
|
| 40 | + */ |
|
| 41 | + protected $_leeway; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Validation constraints. |
|
| 45 | - * |
|
| 46 | - * @var array $_constraints |
|
| 47 | - */ |
|
| 48 | - protected $_constraints; |
|
| 43 | + /** |
|
| 44 | + * Validation constraints. |
|
| 45 | + * |
|
| 46 | + * @var array $_constraints |
|
| 47 | + */ |
|
| 48 | + protected $_constraints; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Explicitly defined validators for named claims. |
|
| 52 | - * |
|
| 53 | - * @var Validator[] $_validators |
|
| 54 | - */ |
|
| 55 | - protected $_validators; |
|
| 50 | + /** |
|
| 51 | + * Explicitly defined validators for named claims. |
|
| 52 | + * |
|
| 53 | + * @var Validator[] $_validators |
|
| 54 | + */ |
|
| 55 | + protected $_validators; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Set of JSON Web Keys usable for the validation. |
|
| 59 | - * |
|
| 60 | - * @var JWKSet $_keys |
|
| 61 | - */ |
|
| 62 | - protected $_keys; |
|
| 57 | + /** |
|
| 58 | + * Set of JSON Web Keys usable for the validation. |
|
| 59 | + * |
|
| 60 | + * @var JWKSet $_keys |
|
| 61 | + */ |
|
| 62 | + protected $_keys; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Whether to allow unsecured JWT's, that is, claims without integrity |
|
| 66 | - * protection nor encryption. |
|
| 67 | - * |
|
| 68 | - * @var bool $_allowUnsecured |
|
| 69 | - */ |
|
| 70 | - protected $_allowUnsecured; |
|
| 64 | + /** |
|
| 65 | + * Whether to allow unsecured JWT's, that is, claims without integrity |
|
| 66 | + * protection nor encryption. |
|
| 67 | + * |
|
| 68 | + * @var bool $_allowUnsecured |
|
| 69 | + */ |
|
| 70 | + protected $_allowUnsecured; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Constructor. |
|
| 74 | - * |
|
| 75 | - * @param array $constraints Optional array of constraints for the |
|
| 76 | - * registered claims |
|
| 77 | - * @param JWKSet $keys Optional set of JSON Web Keys used for signature |
|
| 78 | - * validation and/or decryption |
|
| 79 | - */ |
|
| 80 | - public function __construct(array $constraints = null, JWKSet $keys = null) |
|
| 81 | - { |
|
| 82 | - $this->_refTime = time(); |
|
| 83 | - $this->_leeway = 60; |
|
| 84 | - $this->_constraints = $constraints ? $constraints : array(); |
|
| 85 | - $this->_validators = array(); |
|
| 86 | - $this->_keys = $keys ? $keys : new JWKSet(); |
|
| 87 | - $this->_allowUnsecured = false; |
|
| 88 | - } |
|
| 72 | + /** |
|
| 73 | + * Constructor. |
|
| 74 | + * |
|
| 75 | + * @param array $constraints Optional array of constraints for the |
|
| 76 | + * registered claims |
|
| 77 | + * @param JWKSet $keys Optional set of JSON Web Keys used for signature |
|
| 78 | + * validation and/or decryption |
|
| 79 | + */ |
|
| 80 | + public function __construct(array $constraints = null, JWKSet $keys = null) |
|
| 81 | + { |
|
| 82 | + $this->_refTime = time(); |
|
| 83 | + $this->_leeway = 60; |
|
| 84 | + $this->_constraints = $constraints ? $constraints : array(); |
|
| 85 | + $this->_validators = array(); |
|
| 86 | + $this->_keys = $keys ? $keys : new JWKSet(); |
|
| 87 | + $this->_allowUnsecured = false; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Initialize with a single JSON Web Key. |
|
| 92 | - * |
|
| 93 | - * @param JWK $key JSON Web Key |
|
| 94 | - * @param array $constraints Optional constraints |
|
| 95 | - * @return self |
|
| 96 | - */ |
|
| 97 | - public static function fromJWK(JWK $key, array $constraints = null): self |
|
| 98 | - { |
|
| 99 | - return new self($constraints, new JWKSet($key)); |
|
| 100 | - } |
|
| 90 | + /** |
|
| 91 | + * Initialize with a single JSON Web Key. |
|
| 92 | + * |
|
| 93 | + * @param JWK $key JSON Web Key |
|
| 94 | + * @param array $constraints Optional constraints |
|
| 95 | + * @return self |
|
| 96 | + */ |
|
| 97 | + public static function fromJWK(JWK $key, array $constraints = null): self |
|
| 98 | + { |
|
| 99 | + return new self($constraints, new JWKSet($key)); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Get self with the reference time. |
|
| 104 | - * |
|
| 105 | - * @param int|null $ts Unix timestamp |
|
| 106 | - * @return self |
|
| 107 | - */ |
|
| 108 | - public function withReferenceTime($ts): self |
|
| 109 | - { |
|
| 110 | - $obj = clone $this; |
|
| 111 | - $obj->_refTime = $ts; |
|
| 112 | - return $obj; |
|
| 113 | - } |
|
| 102 | + /** |
|
| 103 | + * Get self with the reference time. |
|
| 104 | + * |
|
| 105 | + * @param int|null $ts Unix timestamp |
|
| 106 | + * @return self |
|
| 107 | + */ |
|
| 108 | + public function withReferenceTime($ts): self |
|
| 109 | + { |
|
| 110 | + $obj = clone $this; |
|
| 111 | + $obj->_refTime = $ts; |
|
| 112 | + return $obj; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Check whether the reference time is set. |
|
| 117 | - * |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function hasReferenceTime(): bool |
|
| 121 | - { |
|
| 122 | - return isset($this->_refTime); |
|
| 123 | - } |
|
| 115 | + /** |
|
| 116 | + * Check whether the reference time is set. |
|
| 117 | + * |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function hasReferenceTime(): bool |
|
| 121 | + { |
|
| 122 | + return isset($this->_refTime); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Get the reference time. |
|
| 127 | - * |
|
| 128 | - * @throws \LogicException |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function referenceTime(): int |
|
| 132 | - { |
|
| 133 | - if (!$this->hasReferenceTime()) { |
|
| 134 | - throw new \LogicException("Reference time not set."); |
|
| 135 | - } |
|
| 136 | - return $this->_refTime; |
|
| 137 | - } |
|
| 125 | + /** |
|
| 126 | + * Get the reference time. |
|
| 127 | + * |
|
| 128 | + * @throws \LogicException |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function referenceTime(): int |
|
| 132 | + { |
|
| 133 | + if (!$this->hasReferenceTime()) { |
|
| 134 | + throw new \LogicException("Reference time not set."); |
|
| 135 | + } |
|
| 136 | + return $this->_refTime; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Get self with the reference time leeway. |
|
| 141 | - * |
|
| 142 | - * @param int $seconds |
|
| 143 | - * @return self |
|
| 144 | - */ |
|
| 145 | - public function withLeeway(int $seconds): self |
|
| 146 | - { |
|
| 147 | - $obj = clone $this; |
|
| 148 | - $obj->_leeway = $seconds; |
|
| 149 | - return $obj; |
|
| 150 | - } |
|
| 139 | + /** |
|
| 140 | + * Get self with the reference time leeway. |
|
| 141 | + * |
|
| 142 | + * @param int $seconds |
|
| 143 | + * @return self |
|
| 144 | + */ |
|
| 145 | + public function withLeeway(int $seconds): self |
|
| 146 | + { |
|
| 147 | + $obj = clone $this; |
|
| 148 | + $obj->_leeway = $seconds; |
|
| 149 | + return $obj; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Get the reference time leeway. |
|
| 154 | - * |
|
| 155 | - * @return int |
|
| 156 | - */ |
|
| 157 | - public function leeway(): int |
|
| 158 | - { |
|
| 159 | - return $this->_leeway; |
|
| 160 | - } |
|
| 152 | + /** |
|
| 153 | + * Get the reference time leeway. |
|
| 154 | + * |
|
| 155 | + * @return int |
|
| 156 | + */ |
|
| 157 | + public function leeway(): int |
|
| 158 | + { |
|
| 159 | + return $this->_leeway; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Get self with a validation constraint. |
|
| 164 | - * |
|
| 165 | - * If the claim does not provide its own validator, an explicit validator |
|
| 166 | - * must be given. |
|
| 167 | - * |
|
| 168 | - * @param string $name Claim name |
|
| 169 | - * @param mixed $constraint Value to check claim against |
|
| 170 | - * @param Validator|null $validator Optional explicit validator |
|
| 171 | - * @return self |
|
| 172 | - */ |
|
| 173 | - public function withConstraint(string $name, $constraint, |
|
| 174 | - Validator $validator = null): self |
|
| 175 | - { |
|
| 176 | - $obj = clone $this; |
|
| 177 | - $obj->_constraints[$name] = $constraint; |
|
| 178 | - if ($validator) { |
|
| 179 | - $obj->_validators[$name] = $validator; |
|
| 180 | - } |
|
| 181 | - return $obj; |
|
| 182 | - } |
|
| 162 | + /** |
|
| 163 | + * Get self with a validation constraint. |
|
| 164 | + * |
|
| 165 | + * If the claim does not provide its own validator, an explicit validator |
|
| 166 | + * must be given. |
|
| 167 | + * |
|
| 168 | + * @param string $name Claim name |
|
| 169 | + * @param mixed $constraint Value to check claim against |
|
| 170 | + * @param Validator|null $validator Optional explicit validator |
|
| 171 | + * @return self |
|
| 172 | + */ |
|
| 173 | + public function withConstraint(string $name, $constraint, |
|
| 174 | + Validator $validator = null): self |
|
| 175 | + { |
|
| 176 | + $obj = clone $this; |
|
| 177 | + $obj->_constraints[$name] = $constraint; |
|
| 178 | + if ($validator) { |
|
| 179 | + $obj->_validators[$name] = $validator; |
|
| 180 | + } |
|
| 181 | + return $obj; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * Get self with the issuer constraint. |
|
| 186 | - * |
|
| 187 | - * @param string $issuer Issuer name |
|
| 188 | - * @return self |
|
| 189 | - */ |
|
| 190 | - public function withIssuer(string $issuer): self |
|
| 191 | - { |
|
| 192 | - return $this->withConstraint(RegisteredClaim::NAME_ISSUER, $issuer); |
|
| 193 | - } |
|
| 184 | + /** |
|
| 185 | + * Get self with the issuer constraint. |
|
| 186 | + * |
|
| 187 | + * @param string $issuer Issuer name |
|
| 188 | + * @return self |
|
| 189 | + */ |
|
| 190 | + public function withIssuer(string $issuer): self |
|
| 191 | + { |
|
| 192 | + return $this->withConstraint(RegisteredClaim::NAME_ISSUER, $issuer); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Get self with the subject constraint. |
|
| 197 | - * |
|
| 198 | - * @param string $subject Subject name |
|
| 199 | - * @return self |
|
| 200 | - */ |
|
| 201 | - public function withSubject(string $subject): self |
|
| 202 | - { |
|
| 203 | - return $this->withConstraint(RegisteredClaim::NAME_SUBJECT, $subject); |
|
| 204 | - } |
|
| 195 | + /** |
|
| 196 | + * Get self with the subject constraint. |
|
| 197 | + * |
|
| 198 | + * @param string $subject Subject name |
|
| 199 | + * @return self |
|
| 200 | + */ |
|
| 201 | + public function withSubject(string $subject): self |
|
| 202 | + { |
|
| 203 | + return $this->withConstraint(RegisteredClaim::NAME_SUBJECT, $subject); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Get self with the audience constraint. |
|
| 208 | - * |
|
| 209 | - * @param string $audience Audience name |
|
| 210 | - * @return self |
|
| 211 | - */ |
|
| 212 | - public function withAudience(string $audience): self |
|
| 213 | - { |
|
| 214 | - return $this->withConstraint(RegisteredClaim::NAME_AUDIENCE, $audience); |
|
| 215 | - } |
|
| 206 | + /** |
|
| 207 | + * Get self with the audience constraint. |
|
| 208 | + * |
|
| 209 | + * @param string $audience Audience name |
|
| 210 | + * @return self |
|
| 211 | + */ |
|
| 212 | + public function withAudience(string $audience): self |
|
| 213 | + { |
|
| 214 | + return $this->withConstraint(RegisteredClaim::NAME_AUDIENCE, $audience); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Get self with the JWT ID constraint. |
|
| 219 | - * |
|
| 220 | - * @param string $id JWT ID |
|
| 221 | - * @return self |
|
| 222 | - */ |
|
| 223 | - public function withID(string $id): self |
|
| 224 | - { |
|
| 225 | - return $this->withConstraint(RegisteredClaim::NAME_JWT_ID, $id); |
|
| 226 | - } |
|
| 217 | + /** |
|
| 218 | + * Get self with the JWT ID constraint. |
|
| 219 | + * |
|
| 220 | + * @param string $id JWT ID |
|
| 221 | + * @return self |
|
| 222 | + */ |
|
| 223 | + public function withID(string $id): self |
|
| 224 | + { |
|
| 225 | + return $this->withConstraint(RegisteredClaim::NAME_JWT_ID, $id); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Check whether a named constraint is present. |
|
| 230 | - * |
|
| 231 | - * @param string $name Claim name |
|
| 232 | - * @return bool |
|
| 233 | - */ |
|
| 234 | - public function hasConstraint(string $name): bool |
|
| 235 | - { |
|
| 236 | - return isset($this->_constraints[$name]); |
|
| 237 | - } |
|
| 228 | + /** |
|
| 229 | + * Check whether a named constraint is present. |
|
| 230 | + * |
|
| 231 | + * @param string $name Claim name |
|
| 232 | + * @return bool |
|
| 233 | + */ |
|
| 234 | + public function hasConstraint(string $name): bool |
|
| 235 | + { |
|
| 236 | + return isset($this->_constraints[$name]); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Get a constraint value by the claim name. |
|
| 241 | - * |
|
| 242 | - * @param string $name Claim name |
|
| 243 | - * @throws \LogicException If constraint is not set |
|
| 244 | - * @return mixed Constraint value |
|
| 245 | - */ |
|
| 246 | - public function constraint(string $name) |
|
| 247 | - { |
|
| 248 | - if (!$this->hasConstraint($name)) { |
|
| 249 | - throw new \LogicException("Constraint $name not set."); |
|
| 250 | - } |
|
| 251 | - return $this->_constraints[$name]; |
|
| 252 | - } |
|
| 239 | + /** |
|
| 240 | + * Get a constraint value by the claim name. |
|
| 241 | + * |
|
| 242 | + * @param string $name Claim name |
|
| 243 | + * @throws \LogicException If constraint is not set |
|
| 244 | + * @return mixed Constraint value |
|
| 245 | + */ |
|
| 246 | + public function constraint(string $name) |
|
| 247 | + { |
|
| 248 | + if (!$this->hasConstraint($name)) { |
|
| 249 | + throw new \LogicException("Constraint $name not set."); |
|
| 250 | + } |
|
| 251 | + return $this->_constraints[$name]; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Check whether a validator is defined for the given claim name. |
|
| 256 | - * |
|
| 257 | - * @param string $name Claim name |
|
| 258 | - * @return bool |
|
| 259 | - */ |
|
| 260 | - public function hasValidator(string $name): bool |
|
| 261 | - { |
|
| 262 | - return isset($this->_validators[$name]); |
|
| 263 | - } |
|
| 254 | + /** |
|
| 255 | + * Check whether a validator is defined for the given claim name. |
|
| 256 | + * |
|
| 257 | + * @param string $name Claim name |
|
| 258 | + * @return bool |
|
| 259 | + */ |
|
| 260 | + public function hasValidator(string $name): bool |
|
| 261 | + { |
|
| 262 | + return isset($this->_validators[$name]); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Get explicitly defined validator by the claim name. |
|
| 267 | - * |
|
| 268 | - * @param string $name Claim name |
|
| 269 | - * @throws \LogicException If validator is not set |
|
| 270 | - * @return Validator |
|
| 271 | - */ |
|
| 272 | - public function validator(string $name): Validator |
|
| 273 | - { |
|
| 274 | - if (!$this->hasValidator($name)) { |
|
| 275 | - throw new \LogicException("Validator $name not set."); |
|
| 276 | - } |
|
| 277 | - return $this->_validators[$name]; |
|
| 278 | - } |
|
| 265 | + /** |
|
| 266 | + * Get explicitly defined validator by the claim name. |
|
| 267 | + * |
|
| 268 | + * @param string $name Claim name |
|
| 269 | + * @throws \LogicException If validator is not set |
|
| 270 | + * @return Validator |
|
| 271 | + */ |
|
| 272 | + public function validator(string $name): Validator |
|
| 273 | + { |
|
| 274 | + if (!$this->hasValidator($name)) { |
|
| 275 | + throw new \LogicException("Validator $name not set."); |
|
| 276 | + } |
|
| 277 | + return $this->_validators[$name]; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Get a set of JSON Web Keys defined in this context. |
|
| 282 | - * |
|
| 283 | - * @return JWKSet |
|
| 284 | - */ |
|
| 285 | - public function keys(): JWKSet |
|
| 286 | - { |
|
| 287 | - return $this->_keys; |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * Get a set of JSON Web Keys defined in this context. |
|
| 282 | + * |
|
| 283 | + * @return JWKSet |
|
| 284 | + */ |
|
| 285 | + public function keys(): JWKSet |
|
| 286 | + { |
|
| 287 | + return $this->_keys; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Get self with 'allow unsecured' flag set. |
|
| 292 | - * |
|
| 293 | - * If the unsecured JWT's are allowed, claims shall be considered valid even |
|
| 294 | - * though they are not signed nor encrypted. |
|
| 295 | - * |
|
| 296 | - * @param bool $allow Whether to allow unsecured JWT's |
|
| 297 | - * @return self |
|
| 298 | - */ |
|
| 299 | - public function withUnsecuredAllowed(bool $allow): self |
|
| 300 | - { |
|
| 301 | - $obj = clone $this; |
|
| 302 | - $obj->_allowUnsecured = $allow; |
|
| 303 | - return $obj; |
|
| 304 | - } |
|
| 290 | + /** |
|
| 291 | + * Get self with 'allow unsecured' flag set. |
|
| 292 | + * |
|
| 293 | + * If the unsecured JWT's are allowed, claims shall be considered valid even |
|
| 294 | + * though they are not signed nor encrypted. |
|
| 295 | + * |
|
| 296 | + * @param bool $allow Whether to allow unsecured JWT's |
|
| 297 | + * @return self |
|
| 298 | + */ |
|
| 299 | + public function withUnsecuredAllowed(bool $allow): self |
|
| 300 | + { |
|
| 301 | + $obj = clone $this; |
|
| 302 | + $obj->_allowUnsecured = $allow; |
|
| 303 | + return $obj; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Check whether the unsecured JWT's are allowed. |
|
| 308 | - * |
|
| 309 | - * @return bool |
|
| 310 | - */ |
|
| 311 | - public function isUnsecuredAllowed(): bool |
|
| 312 | - { |
|
| 313 | - return $this->_allowUnsecured; |
|
| 314 | - } |
|
| 306 | + /** |
|
| 307 | + * Check whether the unsecured JWT's are allowed. |
|
| 308 | + * |
|
| 309 | + * @return bool |
|
| 310 | + */ |
|
| 311 | + public function isUnsecuredAllowed(): bool |
|
| 312 | + { |
|
| 313 | + return $this->_allowUnsecured; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * Validate claims. |
|
| 318 | - * |
|
| 319 | - * @param Claims $claims |
|
| 320 | - * @throws ValidationException If any of the claims is not valid |
|
| 321 | - * @return self |
|
| 322 | - */ |
|
| 323 | - public function validate(Claims $claims): self |
|
| 324 | - { |
|
| 325 | - foreach ($claims as $claim) { |
|
| 326 | - if (!$claim->validateWithContext($this)) { |
|
| 327 | - throw new ValidationException( |
|
| 328 | - "Validation of claim '" . $claim->name() . "' failed."); |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - return $this; |
|
| 332 | - } |
|
| 316 | + /** |
|
| 317 | + * Validate claims. |
|
| 318 | + * |
|
| 319 | + * @param Claims $claims |
|
| 320 | + * @throws ValidationException If any of the claims is not valid |
|
| 321 | + * @return self |
|
| 322 | + */ |
|
| 323 | + public function validate(Claims $claims): self |
|
| 324 | + { |
|
| 325 | + foreach ($claims as $claim) { |
|
| 326 | + if (!$claim->validateWithContext($this)) { |
|
| 327 | + throw new ValidationException( |
|
| 328 | + "Validation of claim '" . $claim->name() . "' failed."); |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + return $this; |
|
| 332 | + } |
|
| 333 | 333 | } |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface EncryptionAlgorithmParameterValue |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Get algorithm type as an 'enc' parameter value. |
|
| 14 | - * |
|
| 15 | - * @return string |
|
| 16 | - */ |
|
| 17 | - public function encryptionAlgorithmParamValue(): string; |
|
| 12 | + /** |
|
| 13 | + * Get algorithm type as an 'enc' parameter value. |
|
| 14 | + * |
|
| 15 | + * @return string |
|
| 16 | + */ |
|
| 17 | + public function encryptionAlgorithmParamValue(): string; |
|
| 18 | 18 | } |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class X509URLParameter extends JWTParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $uri |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $uri) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::PARAM_X509_URL, $uri); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $uri |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $uri) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::PARAM_X509_URL, $uri); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -13,27 +13,27 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EncryptionAlgorithmParameter extends JWTParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $algo Algorithm name |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $algo) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::PARAM_ENCRYPTION_ALGORITHM, $algo); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $algo Algorithm name |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $algo) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::PARAM_ENCRYPTION_ALGORITHM, $algo); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Initialize from EncryptionAlgorithmParameterValue. |
|
| 30 | - * |
|
| 31 | - * @param EncryptionAlgorithmParameterValue $value |
|
| 32 | - * @return self |
|
| 33 | - */ |
|
| 34 | - public static function fromAlgorithm( |
|
| 35 | - EncryptionAlgorithmParameterValue $value): self |
|
| 36 | - { |
|
| 37 | - return new self($value->encryptionAlgorithmParamValue()); |
|
| 38 | - } |
|
| 28 | + /** |
|
| 29 | + * Initialize from EncryptionAlgorithmParameterValue. |
|
| 30 | + * |
|
| 31 | + * @param EncryptionAlgorithmParameterValue $value |
|
| 32 | + * @return self |
|
| 33 | + */ |
|
| 34 | + public static function fromAlgorithm( |
|
| 35 | + EncryptionAlgorithmParameterValue $value): self |
|
| 36 | + { |
|
| 37 | + return new self($value->encryptionAlgorithmParamValue()); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -13,26 +13,26 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class InitializationVectorParameter extends JWTParameter |
| 15 | 15 | { |
| 16 | - use Base64URLValue; |
|
| 16 | + use Base64URLValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $iv Base64url encoded initialization vector |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $iv) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($iv); |
|
| 26 | - parent::__construct(self::PARAM_INITIALIZATION_VECTOR, $iv); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $iv Base64url encoded initialization vector |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $iv) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($iv); |
|
| 26 | + parent::__construct(self::PARAM_INITIALIZATION_VECTOR, $iv); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Get the initialization vector. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function initializationVector(): string |
|
| 35 | - { |
|
| 36 | - return $this->string(); |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Get the initialization vector. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function initializationVector(): string |
|
| 35 | + { |
|
| 36 | + return $this->string(); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class KeyIDParameter extends JWTParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $id |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $id) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::PARAM_KEY_ID, $id); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $id |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $id) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::PARAM_KEY_ID, $id); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -11,24 +11,24 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class PBES2CountParameter extends JWTParameter |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Constructor. |
|
| 16 | - * |
|
| 17 | - * @param int $count |
|
| 18 | - */ |
|
| 19 | - public function __construct(int $count) |
|
| 20 | - { |
|
| 21 | - parent::__construct(self::PARAM_PBES2_COUNT, $count); |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * Constructor. |
|
| 16 | + * |
|
| 17 | + * @param int $count |
|
| 18 | + */ |
|
| 19 | + public function __construct(int $count) |
|
| 20 | + { |
|
| 21 | + parent::__construct(self::PARAM_PBES2_COUNT, $count); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Initialize from a JSON value. |
|
| 26 | - * |
|
| 27 | - * @param int $value |
|
| 28 | - * @return self |
|
| 29 | - */ |
|
| 30 | - public static function fromJSONValue($value): self |
|
| 31 | - { |
|
| 32 | - return new self(intval($value)); |
|
| 33 | - } |
|
| 24 | + /** |
|
| 25 | + * Initialize from a JSON value. |
|
| 26 | + * |
|
| 27 | + * @param int $value |
|
| 28 | + * @return self |
|
| 29 | + */ |
|
| 30 | + public static function fromJSONValue($value): self |
|
| 31 | + { |
|
| 32 | + return new self(intval($value)); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface CompressionAlgorithmParameterValue |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Get compression algorithm type as an 'zip' parameter value. |
|
| 14 | - * |
|
| 15 | - * @return string |
|
| 16 | - */ |
|
| 17 | - public function compressionParamValue(): string; |
|
| 12 | + /** |
|
| 13 | + * Get compression algorithm type as an 'zip' parameter value. |
|
| 14 | + * |
|
| 15 | + * @return string |
|
| 16 | + */ |
|
| 17 | + public function compressionParamValue(): string; |
|
| 18 | 18 | } |