Exemple #1
0
 /**
  * @param string $input
  * @return array
  * @throws InvalidJWTException
  */
 public static function deserialize($input)
 {
     $e_parts = explode(IBasicJWT::SegmentSeparator, $input);
     if (count($e_parts) < 2) {
         throw new InvalidJWTException(sprintf('%s has only 2 or less encoded parts!'));
     }
     $e_header = $e_parts[0];
     $e_payload = $e_parts[1];
     $e_signature = count($e_parts) > 2 ? $e_parts[2] : '';
     $header = JOSEHeaderSerializer::deserialize($e_header);
     $payload = $header->getType()->getString() === 'JWT' ? JWTClaimSetSerializer::deserialize($e_payload) : JWTRawSerializer::deserialize($e_payload);
     $signature = !empty($e_signature) ? JWTRawSerializer::deserialize($e_signature) : '';
     return array($header, $payload, $signature);
 }
Exemple #2
0
 /**
  * @return string
  * @throws JWSInvalidPayloadException
  */
 public function getEncodedPayload()
 {
     if (is_null($this->payload)) {
         throw new JWSInvalidPayloadException('payload is not set!');
     }
     $enc_payload = '';
     if ($this->payload->isClaimSet() && $this->payload instanceof IJWSPayloadClaimSetSpec) {
         $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet());
     } else {
         $enc_payload = JWTRawSerializer::serialize($this->payload->getRaw());
     }
     return $enc_payload;
 }