Skip to content

Commit 926ef39

Browse files
authored
Merge pull request #18 from adhocore/noverify-option
Noverify option
2 parents a38fa26 + 3d8b046 commit 926ef39

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/JWT.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,23 @@ public function encode(array $payload, array $header = []): string
143143
* Decode JWT token and return original payload.
144144
*
145145
* @param string $token
146+
* @param bool $verify
146147
*
147148
* @throws JWTException
148149
*
149150
* @return array
150151
*/
151-
public function decode(string $token): array
152+
public function decode(string $token, bool $verify = true): array
152153
{
153154
if (\substr_count($token, '.') < 2) {
154155
throw new JWTException('Invalid token: Incomplete segments', static::ERROR_TOKEN_INVALID);
155156
}
156157

157158
$token = \explode('.', $token, 3);
159+
if (!$verify) {
160+
return (array) $this->urlSafeDecode($token[1]);
161+
}
162+
158163
$this->validateHeader((array) $this->urlSafeDecode($token[0]));
159164

160165
// Validate signature.

tests/JWTTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function test_kid()
116116
$token = $jwt->encode($payload = ['a' => 1, 'exp' => time() + 1000], ['kid' => 'key2']);
117117

118118
$this->assertSame($payload, $jwt->decode($token));
119+
$this->assertSame($payload, $jwt->decode($token, false));
119120

120121
return $jwt;
121122
}

0 commit comments

Comments
 (0)