ttl = $ttl; $this->secretKey = $secretKey; $this->algorithm = $algorithm; $this->issuer = $issuer; } public function generate(array $payload): string { $defaultClaims = []; $defaultClaims['iat'] = $payload['iat'] ?? (new DateTimeImmutable())->getTimestamp(); $defaultClaims['exp'] = $payload['exp'] ?? ((new DateTimeImmutable())->modify("+{$this->ttl} seconds")->getTimestamp()); $finalPayload = array_merge($payload, $defaultClaims); return JWT::encode( payload: $finalPayload, key: $this->secretKey, alg: $this->algorithm ); } public function validate(string $token): object { return JWT::decode( jwt: $token, keyOrKeyArray: new Key( keyMaterial: $this->secretKey, algorithm: $this->algorithm ) ); } }