/** * @param string $jwt * @return Token */ public function deserialize($jwt) { $token = new Token(); list($encodedHeader, $encodedPayload, $encodedSignature) = explode('.', $jwt); $decodedHeader = $this->encoding->decode($encodedHeader); $decodedPayload = $this->encoding->decode($encodedPayload); $decodedSignature = $this->encoding->decode($encodedSignature); foreach ($this->parseHeaders($decodedHeader) as $header) { $token->addHeader($header); } foreach ($this->parsePayload($decodedPayload) as $claim) { $token->addClaim($claim); } $token->setSignature($decodedSignature); return $token; }
/** * @param string $jwt * * @return Token * @throws \InvalidArgumentException */ public function deserialize($jwt) { $token = new Token(); if (empty($jwt)) { throw new \InvalidArgumentException('Not a valid JWT string passed for deserialization'); } list($encodedHeader, $encodedPayload, $encodedSignature) = array_pad(explode('.', $jwt, 3), 3, null); $decodedHeader = $this->encoding->decode($encodedHeader); $decodedPayload = $this->encoding->decode($encodedPayload); $decodedSignature = $this->encoding->decode($encodedSignature); foreach ($this->parseHeaders($decodedHeader) as $header) { $token->addHeader($header); } foreach ($this->parsePayload($decodedPayload) as $claim) { $token->addClaim($claim); } $token->setSignature($decodedSignature); return $token; }