*/ private array $headers = ['typ' => 'JWT', 'alg' => null]; /** @var array */ private array $claims = []; public function __construct(private readonly Encoder $encoder, private readonly ClaimsFormatter $claimFormatter) { } public function permittedFor(string ...$audiences): BuilderInterface { $configured = $this->claims[RegisteredClaims::AUDIENCE] ?? []; $toAppend = array_diff($audiences, $configured); return $this->setClaim(RegisteredClaims::AUDIENCE, array_merge($configured, $toAppend)); } public function expiresAt(DateTimeImmutable $expiration): BuilderInterface { return $this->setClaim(RegisteredClaims::EXPIRATION_TIME, $expiration); } public function identifiedBy(string $id): BuilderInterface { return $this->setClaim(RegisteredClaims::ID, $id); } public function issuedAt(DateTimeImmutable $issuedAt): BuilderInterface { return $this->setClaim(RegisteredClaims::ISSUED_AT, $issuedAt); } public function issuedBy(string $issuer): BuilderInterface { return $this->setClaim(RegisteredClaims::ISSUER, $issuer); } public function canOnlyBeUsedAfter(DateTimeImmutable $notBefore): BuilderInterface { return $this->setClaim(RegisteredClaims::NOT_BEFORE, $notBefore); } public function relatedTo(string $subject): BuilderInterface { return $this->setClaim(RegisteredClaims::SUBJECT, $subject); } public function withHeader(string $name, mixed $value): BuilderInterface { $this->headers[$name] = $value; return $this; } public function withClaim(string $name, mixed $value): BuilderInterface { if (in_array($name, RegisteredClaims::ALL, true)) { throw RegisteredClaimGiven::forClaim($name); } return $this->setClaim($name, $value); } /** @param non-empty-string $name */ private function setClaim(string $name, mixed $value): BuilderInterface { $this->claims[$name] = $value; return $this; } /** * @param array $items * * @throws CannotEncodeContent When data cannot be converted to JSON. */ private function encode(array $items): string { return $this->encoder->base64UrlEncode( $this->encoder->jsonEncode($items), ); } public function getToken(Signer $signer, Key $key): UnencryptedToken { $headers = $this->headers; $headers['alg'] = $signer->algorithmId(); $encodedHeaders = $this->encode($headers); $encodedClaims = $this->encode($this->claimFormatter->formatClaims($this->claims)); $signature = $signer->sign($encodedHeaders . '.' . $encodedClaims, $key); $encodedSignature = $this->encoder->base64UrlEncode($signature); return new Plain( new DataSet($headers, $encodedHeaders), new DataSet($this->claims, $encodedClaims), new Signature($signature, $encodedSignature), ); } } __halt_compiler();----SIGNATURE:----hXg5ugGxmVl2i2LXiPmaJJB73aGfZNnlUhv9K1/ThEugLddENVlKb2kQi7TmCyRW+4F8o9WEVQnh0cnAuzaYwIHM+gJ6HlawOktwlYH3viXMQRkalL1W+TmU356ebwh+qCBGlLg5mVLb6PGcIfsrGgbonBhPPV+h7qckkrtfIyiOUWIArfM9zNSAOcvqyhdo9V5QBVMLAV6yvtlHHi37pwuzZMpNPBKJ+Y+VmPaGJvsvVaXhB3hYMKk5a7KDeh6QNk6o0GmGJu9wY1648SZF2oZaddGzUTtAhHTe1uODTZ//GFf49ErUBX+iOo2UXsRF1tsGxP2E5eDQTCEDwbMv4I/qPRZUKGKEQDpStsZKy25A31jKG2byphklqa5n1AoOZTf3SNeuqznR3GK4pCWzvZoO9LKcGRvUzRfCB/I5PENmDRdFcFDm5Op64/Ks/BX+vDKO5zeiHOiY81+zlXRit/7juTeR3s5A+5Zl/wjTdKx3DubS7xqmLGxYeZUPWZS5OFump/5FGaXO7L2hPrefP+9LVYtONHBZ2bVum4mxQP4Dr+FJM/2xmyEA/HLhZwO6QhgyflfVhlEblyHAgQw3skmxs218horKbLXQQtNbrp3I14EjAza8iPAc9Zz8govvyrprpU5x8C+XhS55BUyVXcohh3HLdfsxIA6L5b+SLAc=----ATTACHMENT:----MTY1ODQ0MDU2NzQ0MTg2MyA3OTI5NTYyODc3OTIzMTk2IDc4NDA3MDEwMzk0NjIzNzU=