*/ private array $customClaims = []; private Duration $ttl; private function __construct(private string $uid) { $this->ttl = Duration::fromDateIntervalSpec(self::DEFAULT_TTL); } public static function forUid(string $uid): self { return new self($uid); } public function withTenantId(string $tenantId): self { $action = clone $this; $action->tenantId = $tenantId; return $action; } public function withChangedUid(string $uid): self { $action = clone $this; $action->uid = $uid; return $action; } public function withCustomClaim(string $name, mixed $value): self { $action = clone $this; $action->customClaims[$name] = $value; return $action; } /** * @param array $claims */ public function withCustomClaims(array $claims): self { $action = clone $this; $action->customClaims = $claims; return $action; } /** * @param array $claims */ public function withAddedCustomClaims(array $claims): self { $action = clone $this; $action->customClaims = [...$action->customClaims, ...$claims]; return $action; } public function withTimeToLive(Duration|DateInterval|string|int $ttl): self { $ttl = Duration::make($ttl); $minTtl = Duration::fromDateIntervalSpec(self::MINIMUM_TTL); $maxTtl = Duration::fromDateIntervalSpec(self::MAXIMUM_TTL); if ($ttl->isSmallerThan($minTtl) || $ttl->isLargerThan($maxTtl)) { $message = 'The expiration time of a custom token must be between %s and %s, but got %s'; throw new InvalidArgumentException(sprintf($message, $minTtl, $maxTtl, $ttl)); } $action = clone $this; $action->ttl = $ttl; return $action; } public function uid(): string { return $this->uid; } public function tenantId(): ?string { return $this->tenantId; } /** * @return array */ public function customClaims(): array { return $this->customClaims; } public function timeToLive(): Duration { return $this->ttl; } }