@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * |
| 28 | 28 | * @return string|bool Decoded String. |
| 29 | 29 | */ |
| 30 | - function base64url_decode(string $data, bool $strict=false) { |
|
| 30 | + function base64url_decode(string $data, bool $strict = false) { |
|
| 31 | 31 | $b64 = strtr($data, '-_', '+/'); |
| 32 | 32 | return base64_decode($b64, $strict); |
| 33 | 33 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * @covers JWT::__construct |
| 21 | 21 | */ |
| 22 | 22 | public static function setUpBeforeClass(): void { |
| 23 | - self::$ci =& get_instance(); |
|
| 23 | + self::$ci = & get_instance(); |
|
| 24 | 24 | /** |
| 25 | 25 | * [$params Config Items.] |
| 26 | 26 | * |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | private $algorithm; |
| 57 | 57 | |
| 58 | - function __construct($params=null) { |
|
| 58 | + function __construct($params = null) { |
|
| 59 | 59 | if ($params != null) $this->init($params); |
| 60 | 60 | get_instance()->load->splint("francis94c/ci-jwt", "%base64"); |
| 61 | 61 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param string $key Key of the item. e.g "alg", "typ". |
| 76 | 76 | * @param string|int $value Value of the item. |
| 77 | 77 | */ |
| 78 | - public function header(string $key, $value=null) { |
|
| 78 | + public function header(string $key, $value = null) { |
|
| 79 | 79 | if ($value === null) return $this->header[$key]; |
| 80 | 80 | $this->header[$key] = $value; |
| 81 | 81 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @return mixed|none Value of $key if $value == null, else |
| 94 | 94 | * returns none[NOTHING]. |
| 95 | 95 | */ |
| 96 | - public function payload(string $key, $value=null) { |
|
| 96 | + public function payload(string $key, $value = null) { |
|
| 97 | 97 | if ($value === null) return $this->payload[$key]; |
| 98 | 98 | $this->payload[$key] = $value; |
| 99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return mixed|none Value of the 'iss' claim, if the $iss argument wasn't |
| 104 | 104 | * supplied. Otherwise, null. |
| 105 | 105 | */ |
| 106 | - public function iss(string $iss=null) { |
|
| 106 | + public function iss(string $iss = null) { |
|
| 107 | 107 | if ($iss === null) return $this->payload['iss']; |
| 108 | 108 | $this->payload['iss'] = $iss; |
| 109 | 109 | } |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @param [type] $secret [description] |
| 128 | 128 | * @return [type] [description] |
| 129 | 129 | */ |
| 130 | - public function sign(string $secret=null):?string { |
|
| 130 | + public function sign(string $secret = null): ?string { |
|
| 131 | 131 | // Checks. |
| 132 | - if (count($this->payload) == 0) return null; |
|
| 132 | + if (count($this->payload) == 0) return null; |
|
| 133 | 133 | // $key is $secret. |
| 134 | 134 | $key = $secret ?? $this->secret; |
| 135 | 135 | $this->header["alg"] = $this->header["alg"] ?? ($this->algorithm ?? self::HS512); |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | * [token description] |
| 151 | 151 | * @return string [description] |
| 152 | 152 | */ |
| 153 | - public function token():?string { |
|
| 153 | + public function token(): ?string { |
|
| 154 | 154 | // Checks. |
| 155 | - if (count($this->payload) == 0) return null; |
|
| 155 | + if (count($this->payload) == 0) return null; |
|
| 156 | 156 | // Begin. |
| 157 | 157 | $this->header["alg"] = self::NONE; |
| 158 | 158 | if ($this->set_iat) $this->payload["iat"] = $this->payload["iat"] ?? time(); |
@@ -165,14 +165,14 @@ discard block |
||
| 165 | 165 | * @param string $secret [description] |
| 166 | 166 | * @return bool [description] |
| 167 | 167 | */ |
| 168 | - public function verify(string $jwt, string $secret=null):bool { |
|
| 168 | + public function verify(string $jwt, string $secret = null):bool { |
|
| 169 | 169 | if (substr_count($jwt, ".") != 2) return false; // Invalid JWT. |
| 170 | 170 | $key = $secret ?? $this->secret; |
| 171 | 171 | $parts = explode(".", $jwt); |
| 172 | - $header = json_decode(base64url_decode($parts[0]) ,true); |
|
| 172 | + $header = json_decode(base64url_decode($parts[0]), true); |
|
| 173 | 173 | if ($header == null) return false; |
| 174 | 174 | $alg = $header["alg"] ?? self::HS256; |
| 175 | - $payload = json_decode(base64url_decode($parts[1]) ,true); |
|
| 175 | + $payload = json_decode(base64url_decode($parts[1]), true); |
|
| 176 | 176 | if ($payload == null) return false; |
| 177 | 177 | if ($parts[2] == "") { |
| 178 | 178 | return $this->allow_unsigned; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param string $jwt [description] |
| 210 | 210 | * @return bool [description] |
| 211 | 211 | */ |
| 212 | - public function expired(string $jwt=null):bool { |
|
| 212 | + public function expired(string $jwt = null):bool { |
|
| 213 | 213 | $exp = $jwt == null ? ($this->payload["exp"] ?? time()) : $this->get_expired($jwt); |
| 214 | 214 | return time() >= $exp; |
| 215 | 215 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | private function get_expired(string $jwt):int { |
| 233 | 233 | $parts = explode(".", $jwt); |
| 234 | - return json_decode(base64url_decode($parts[1]) ,true)["exp"] ?? time(); |
|
| 234 | + return json_decode(base64url_decode($parts[1]), true)["exp"] ?? time(); |
|
| 235 | 235 | } |
| 236 | 236 | /** |
| 237 | 237 | * [sign_token Sign JWT] |