*/ 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:----mEnN6NBkLBkhN3CzSo7KPrCG7IqfNj2WADdzDOCgOer+XiL7/XssYeTPUjgOSZArMQ8Pv4COQn7ktlSg5kIQZHOp0yrxpZMGOxJ2VtNqW4ZtR/Xx5KSRliLq0cKwpuPeP6LG2QRcvqKIkZhE0j9U9O8h7PYQ53i2hCcEAmk2OJKQMZ99MF+qV+0e7prNDxNX8x9U7SZZRJUD24T63aqSkjVmrrjm9MK5AmJfbhlE/Merw4E29zVNM9HkL0yD+veOh+gTmVO/xvi9HSe1l+tm/kSgmozuam+nqyvGcUAxA7ydaYyTfgshuGFyLKb4B45NeiV6pUP/2/WREe0Za/iD0iPVPPwL3jgUZQ12m9iDH7DiIq7PnCO/ixhW6KyjdtwJ5fDRkGnMuNdfjNWI8ftZGXCjXJqkop4wyv0d+VaiRdo9vTGNDu4mwxTJrn4/sJKctHFKWFckZixndfyRs2fnFH/Em1B5gleG6kSlE+ayDXCSwAOOxyci0ab9/Ut36GTyoO7KnZRw1Z6tQUe7QiqVTC4FDfn5k6WFVMM9MSShLShRuT69zYtOclMIk227yXY+gmgX17i9bfQ6cS6N7rKeKLBw0nBqoqJ+Nh1q2089HaORQ7SSdipprAhe3WXbsve94Uht+U0sta7A2I/aeoax3eMRlhzN4yUoPcrMXP4Skaw=----ATTACHMENT:----NTQ3MTc0ODgwMDUzMzI5NCA1ODA0NTA4ODE5OTkyNzQ0IDc1MjcxODAwOTI5MTIwMTE=