*/ 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:----wKxf3gyLwW9l7A36/AdnjXbyTc6OPZ4rDnWV1hapRwOYUaHmSo6TQMnes7QMM4K6DG+G+6V3IgKr7Yb9ShkR1+/qErbnm7YkrzMkbeq/6CZ1NjMQzqtvZGqof917TVxZ24/E9CG2fwthsJt0tDvzKUt+9TRdywQb4zMkA+16cv7RPwE2tJevL1t4fMn26UwE54RVF0qOEsRHndnvPjkmPmkHpzkliiYondz+HgoiuIhX+wd8DI/rhUWdCg7TbjUmylxrvv/DgoJZSACaGn1r+shsx9X2tDRnETAAFiNOEiNbxt8oBtEzeTuePK0n0TO1V7aqoHf4xj19MkI4qHE93JRIDntOLM5x8FAyGo75wxJVs5LFX/pGhD38hTincxu0BXaC8lObA9ay4rObjkiIJxBQArMak5vh5c1+h12bVV9tpwLmi97BUgjy7A9A/pGMxMwGHt4VIe67j2N868Xu+wYKJTYrxeabGm7K3Q86tXpIF/scq0VrfJ6tNkM96uooUmkAtxcDb/e9c5tzKf2Yl/qq5dSQKGtBkZa53qPJfPM9XWABr9v03qut/CLfG2db3I1N/kMUtypWgGSXdJNM0HcOMxkUB+7aqr3s0gQ7KmkpcsuYN00714dt7O3TRxd4g+cgU7P71W71ENuXpuKVipMwtYhc9GQAhRvaFTJNLig=----ATTACHMENT:----NDUyNDg2NzcyODE4MzE4NiAzMDI4MTIzOTg3NzAzNDMwIDg0ODgwMDUwNTk2NjkzNTc=