@@ -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 | * |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | private $auto_expire; |
50 | 50 | |
51 | - function __construct($params=null) { |
|
51 | + function __construct($params = null) { |
|
52 | 52 | if ($params != null) $this->init($params); |
53 | 53 | get_instance()->load->splint("francis94c/ci-jwt", "%base64"); |
54 | 54 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param [type] $secret [description] |
105 | 105 | * @return [type] [description] |
106 | 106 | */ |
107 | - public function sign(string $secret=null):?string { |
|
107 | + public function sign(string $secret = null): ?string { |
|
108 | 108 | // Checks. |
109 | - if (count($this->payload) == 0) return null; |
|
109 | + if (count($this->payload) == 0) return null; |
|
110 | 110 | // $key is $secret. |
111 | 111 | $key = $secret ?? $this->secret; |
112 | 112 | $this->header["alg"] = $this->header["alg"] ?? self::HS256; |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * [token description] |
128 | 128 | * @return string [description] |
129 | 129 | */ |
130 | - public function token():?string { |
|
130 | + public function token(): ?string { |
|
131 | 131 | // Checks. |
132 | - if (count($this->payload) == 0) return null; |
|
132 | + if (count($this->payload) == 0) return null; |
|
133 | 133 | // Begin. |
134 | 134 | $this->header["alg"] = self::NONE; |
135 | 135 | if ($this->set_iat) $this->payload["iat"] = $this->payload["iat"] ?? time(); |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | * @param string $secret [description] |
143 | 143 | * @return bool [description] |
144 | 144 | */ |
145 | - public function verify(string $jwt, string $secret=null):bool { |
|
145 | + public function verify(string $jwt, string $secret = null):bool { |
|
146 | 146 | if (substr_count($jwt, ".") != 2) return false; // Invalid JWT. |
147 | 147 | $key = $secret ?? $this->secret; |
148 | 148 | $parts = explode(".", $jwt); |
149 | - $header = json_decode(base64url_decode($parts[0]) ,true); |
|
149 | + $header = json_decode(base64url_decode($parts[0]), true); |
|
150 | 150 | if ($header == null) return false; |
151 | 151 | $alg = $header["alg"] ?? self::HS256; |
152 | - $payload = json_decode(base64url_decode($parts[1]) ,true); |
|
152 | + $payload = json_decode(base64url_decode($parts[1]), true); |
|
153 | 153 | if ($payload == null) return false; |
154 | 154 | if ($parts[2] == "") { |
155 | 155 | return $this->allow_unsigned; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param string $jwt [description] |
187 | 187 | * @return bool [description] |
188 | 188 | */ |
189 | - public function expired(string $jwt=null):bool { |
|
189 | + public function expired(string $jwt = null):bool { |
|
190 | 190 | $exp = $jwt == null ? ($this->payload["exp"] ?? time()) : $this->get_expired($jwt); |
191 | 191 | return time() >= $exp; |
192 | 192 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | private function get_expired(string $jwt):int { |
210 | 210 | $parts = explode(".", $jwt); |
211 | - return json_decode(base64url_decode($parts[1]) ,true)["exp"] ?? time(); |
|
211 | + return json_decode(base64url_decode($parts[1]), true)["exp"] ?? time(); |
|
212 | 212 | } |
213 | 213 | /** |
214 | 214 | * [sign_token Sign JWT] |