Skip to content

Commit

Permalink
Merge pull request #18 from adhocore/noverify-option
Browse files Browse the repository at this point in the history
Noverify option
  • Loading branch information
adhocore committed Sep 30, 2020
2 parents a38fa26 + 3d8b046 commit 926ef39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,23 @@ public function encode(array $payload, array $header = []): string
* Decode JWT token and return original payload.
*
* @param string $token
* @param bool $verify
*
* @throws JWTException
*
* @return array
*/
public function decode(string $token): array
public function decode(string $token, bool $verify = true): array
{
if (\substr_count($token, '.') < 2) {
throw new JWTException('Invalid token: Incomplete segments', static::ERROR_TOKEN_INVALID);
}

$token = \explode('.', $token, 3);
if (!$verify) {
return (array) $this->urlSafeDecode($token[1]);
}

$this->validateHeader((array) $this->urlSafeDecode($token[0]));

// Validate signature.
Expand Down
1 change: 1 addition & 0 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function test_kid()
$token = $jwt->encode($payload = ['a' => 1, 'exp' => time() + 1000], ['kid' => 'key2']);

$this->assertSame($payload, $jwt->decode($token));
$this->assertSame($payload, $jwt->decode($token, false));

return $jwt;
}
Expand Down

0 comments on commit 926ef39

Please sign in to comment.