Skip to content

Commit

Permalink
feat: decode option without verify exp or sign
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore authored Sep 30, 2020
1 parent a38fa26 commit e2dc2a6
Showing 1 changed file with 6 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

0 comments on commit e2dc2a6

Please sign in to comment.