@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @date 2020-03-28 |
| 70 | 70 | * @param [type] $params Config array. |
| 71 | 71 | */ |
| 72 | - public function __construct(?array $params=null) |
|
| 72 | + public function __construct(?array $params = null) |
|
| 73 | 73 | { |
| 74 | 74 | if ($params != null) $this->init($params); |
| 75 | 75 | get_instance()->load->splint("francis94c/ci-jwt", "%base64"); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @param string $key Key of the item. e.g "alg", "typ". |
| 105 | 105 | * @param string|int $value Value of the item. |
| 106 | 106 | */ |
| 107 | - public function header(string $key, $value=null) |
|
| 107 | + public function header(string $key, $value = null) |
|
| 108 | 108 | { |
| 109 | 109 | if ($value === null) return $this->header[$key]; |
| 110 | 110 | $this->header[$key] = $value; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @return mixed|none Value of $key if $value == null, else |
| 128 | 128 | * returns none[NOTHING]. |
| 129 | 129 | */ |
| 130 | - public function payload(string $key, $value=null) |
|
| 130 | + public function payload(string $key, $value = null) |
|
| 131 | 131 | { |
| 132 | 132 | if ($value === null) return $this->payload[$key]; |
| 133 | 133 | $this->payload[$key] = $value; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return mixed|none Value of the 'iss' claim, if the $iss argument wasn't |
| 155 | 155 | * supplied. Otherwise, null. |
| 156 | 156 | */ |
| 157 | - public function iss(string $iss=null) |
|
| 157 | + public function iss(string $iss = null) |
|
| 158 | 158 | { |
| 159 | 159 | if ($iss === null) return $this->payload['iss']; |
| 160 | 160 | $this->payload['iss'] = $iss; |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | * @param [type] $secret [description] |
| 187 | 187 | * @return [type] [description] |
| 188 | 188 | */ |
| 189 | - public function sign(string $secret=null):?string { |
|
| 189 | + public function sign(string $secret = null): ?string { |
|
| 190 | 190 | // Checks. |
| 191 | - if (count($this->payload) == 0) return null; |
|
| 191 | + if (count($this->payload) == 0) return null; |
|
| 192 | 192 | // $key is $secret. |
| 193 | 193 | $key = $secret ?? $this->secret; |
| 194 | 194 | $this->header["alg"] = $this->header["alg"] ?? ($this->algorithm ?? self::HS512); |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | * [token description] |
| 211 | 211 | * @return string [description] |
| 212 | 212 | */ |
| 213 | - public function token():?string |
|
| 213 | + public function token(): ?string |
|
| 214 | 214 | { |
| 215 | 215 | // Checks. |
| 216 | - if (count($this->payload) == 0) return null; |
|
| 216 | + if (count($this->payload) == 0) return null; |
|
| 217 | 217 | // Begin. |
| 218 | 218 | $this->header["alg"] = self::NONE; |
| 219 | 219 | if ($this->set_iat) $this->payload["iat"] = $this->payload["iat"] ?? time(); |
@@ -227,14 +227,14 @@ discard block |
||
| 227 | 227 | * @param string $secret [description] |
| 228 | 228 | * @return bool [description] |
| 229 | 229 | */ |
| 230 | - public function verify(string $jwt, string $secret=null):bool { |
|
| 230 | + public function verify(string $jwt, string $secret = null):bool { |
|
| 231 | 231 | if (substr_count($jwt, ".") != 2) return false; // Invalid JWT. |
| 232 | 232 | $key = $secret ?? $this->secret; |
| 233 | 233 | $parts = explode(".", $jwt); |
| 234 | - $header = json_decode(base64url_decode($parts[0]) ,true); |
|
| 234 | + $header = json_decode(base64url_decode($parts[0]), true); |
|
| 235 | 235 | if ($header == null) return false; |
| 236 | 236 | $alg = $this->algorithm ?? $header["alg"] ?? self::HS256; |
| 237 | - $payload = json_decode(base64url_decode($parts[1]) ,true); |
|
| 237 | + $payload = json_decode(base64url_decode($parts[1]), true); |
|
| 238 | 238 | if ($payload == null) return false; |
| 239 | 239 | if ($parts[2] == "") { |
| 240 | 240 | return $this->allow_unsigned; |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @param string $jwt [description] |
| 275 | 275 | * @return bool [description] |
| 276 | 276 | */ |
| 277 | - public function expired(string $jwt=null):bool { |
|
| 277 | + public function expired(string $jwt = null):bool { |
|
| 278 | 278 | $exp = $jwt == null ? ($this->payload["exp"] ?? time() + 4) : $this->get_expired($jwt); |
| 279 | 279 | return time() >= $exp; |
| 280 | 280 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | private function get_expired(string $jwt):int |
| 300 | 300 | { |
| 301 | 301 | $parts = explode(".", $jwt); |
| 302 | - return json_decode(base64url_decode($parts[1]) ,true)["exp"] ?? time() + 4; |
|
| 302 | + return json_decode(base64url_decode($parts[1]), true)["exp"] ?? time() + 4; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |