@@ -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; |