/** * @param IJWTSnapshot $jwt_snapshot * @return string */ public static function serialize(IJWTSnapshot $jwt_snapshot) { list($header, $payload, $signature) = $jwt_snapshot->take(); $e_header = JOSEHeaderSerializer::serialize($header); $e_payload = $header->getType()->getString() === 'JWT' ? JWTClaimSetSerializer::serialize($payload) : JWTRawSerializer::serialize($payload); $e_signature = JWTRawSerializer::serialize($signature); return sprintf('%s.%s.%s', $e_header, $e_payload, $e_signature); }
/** * @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; }