public static function generate(array $payload, $key)
    {
        // Check if payload is array
        if (!is_array($payload)) {
            throw new InvalidArgumentException('Token payload must be an array');
        }

        // Check if payload or key is empty
        if (empty($payload) || empty($key)) {
            throw new InvalidArgumentException('Both payload and key must have a value');
        }

        // Encode with json and base64
        $payloadEncoded = base64_encode(json_encode($payload, JSON_FORCE_OBJECT));

        // Create signature
        $signature = hash_hmac($algo = 'SHA256', $data = $payloadEncoded, $key);

        // Return combined key
        return implode('.', [$payloadEncoded, $signature]);
    }