@@ -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 | * |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | private $set_iat = true; |
| 43 | 43 | |
| 44 | - function __construct($params=null) { |
|
| 44 | + function __construct($params = null) { |
|
| 45 | 45 | if ($params != null) $this->init($params); |
| 46 | 46 | get_instance()->load->splint("francis94c/ci-jwt", "%base64"); |
| 47 | 47 | } |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | * @param [type] $secret [description] |
| 97 | 97 | * @return [type] [description] |
| 98 | 98 | */ |
| 99 | - public function sign(string $secret=null):?string { |
|
| 99 | + public function sign(string $secret = null): ?string { |
|
| 100 | 100 | // Checks. |
| 101 | - if (count($this->payload) == 0) return null; |
|
| 101 | + if (count($this->payload) == 0) return null; |
|
| 102 | 102 | // $key is $secret. |
| 103 | 103 | $key = $secret ?? $this->secret; |
| 104 | 104 | $this->header["alg"] = $this->header["alg"] ?? self::HS256; |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * [token description] |
| 116 | 116 | * @return string [description] |
| 117 | 117 | */ |
| 118 | - public function token():?string { |
|
| 118 | + public function token(): ?string { |
|
| 119 | 119 | // Checks. |
| 120 | - if (count($this->payload) == 0) return null; |
|
| 120 | + if (count($this->payload) == 0) return null; |
|
| 121 | 121 | // Begin. |
| 122 | 122 | $this->header["alg"] = self::NONE; |
| 123 | 123 | if ($this->set_iat) $this->payload["iat"] = $this->payload["iat"] ?? time(); |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @param string $secret [description] |
| 130 | 130 | * @return bool [description] |
| 131 | 131 | */ |
| 132 | - public function verify(string $jwt, string $secret=null):bool { |
|
| 132 | + public function verify(string $jwt, string $secret = null):bool { |
|
| 133 | 133 | if (substr_count($jwt, ".") != 2) return false; // Invalid JWT. |
| 134 | 134 | $key = $secret ?? $this->secret; |
| 135 | 135 | $parts = explode(".", $jwt); |
| 136 | - $header = json_decode(base64url_decode($parts[0]) ,true); |
|
| 136 | + $header = json_decode(base64url_decode($parts[0]), true); |
|
| 137 | 137 | if ($header == null) return false; |
| 138 | 138 | $alg = $header["alg"] ?? self::HS256; |
| 139 | - $payload = json_decode(base64url_decode($parts[1]) ,true); |
|
| 139 | + $payload = json_decode(base64url_decode($parts[1]), true); |
|
| 140 | 140 | if ($payload == null) return false; |
| 141 | 141 | if ($parts[2] == "") { |
| 142 | 142 | return $this->allow_unsigned; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @param string $jwt [description] |
| 164 | 164 | * @return bool [description] |
| 165 | 165 | */ |
| 166 | - public function expired(string $jwt=null):bool { |
|
| 166 | + public function expired(string $jwt = null):bool { |
|
| 167 | 167 | $exp = $jwt == null ? ($this->payload["exp"] ?? time()) : $this->get_expired($jwt); |
| 168 | 168 | return time() >= $exp; |
| 169 | 169 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | private function get_expired(string $jwt):int { |
| 187 | 187 | $parts = explode(".", $jwt); |
| 188 | - return json_decode(base64url_decode($parts[1]) ,true)["exp"] ?? time(); |
|
| 188 | + return json_decode(base64url_decode($parts[1]), true)["exp"] ?? time(); |
|
| 189 | 189 | } |
| 190 | 190 | /** |
| 191 | 191 | * [sign_token Sign JWT] |