etherpad-lite-client icon indicating copy to clipboard operation
etherpad-lite-client copied to clipboard

Invalid API key in `Client.php`

Open sonn-gamm opened this issue 8 years ago • 2 comments

Hi, thanks for the great plugin.

I moved the API key generate by etherpad-lite from the main.php of the wiki I am working on, to etherpad-lite-client's Client.php.

Therefore, when creating a new instance in main.php, I am doing like this:

$instance = new EtherpadLite\Client($apiKey, $baseUrl);

This throws the following error though:

Uncaught exception 'InvalidArgumentException' with message '[] is not a valid API key

I expect it to work and being more of a discrete way to store the API key, but it's not. If I replace the above $instance with

$instance = new EtherpadLite\Client('api-key-xxxx', $baseUrl);

etherpad-lite-client works.

Any idea?

sonn-gamm avatar Jun 19 '17 17:06 sonn-gamm

Hi, I also have similar issue. I enabled etherpad Note module in Space and can create a note. But when I want to edit it, it didn't work. The error message shows as follows: InvalidArgumentException [] is not a valid API key

1. in /var/www/html/humhub/protected/modules/notes/libs/EtherpadLiteClient.php at line 25
16171819202122232425262728293031323334

    const CODE_INVALID_FUNCTION = 3;
    const CODE_INVALID_API_KEY = 4;
 
    protected $apiKey = "";
    protected $baseUrl = "http://localhost:9001/api";
 
    public function __construct($apiKey, $baseUrl = null)
    {
        if (strlen($apiKey) < 1) {
            throw new InvalidArgumentException("[{$apiKey}] is not a valid API key");
        }
        $this->apiKey = $apiKey;
 
        if (isset($baseUrl)) {
            $this->baseUrl = $baseUrl;
        }
        if (!filter_var($this->baseUrl, FILTER_VALIDATE_URL)) {
            throw new InvalidArgumentException("[{$this->baseUrl}] is not a valid URL");
        }

2. in /var/www/html/humhub/protected/modules/notes/libs/EtherpadHelper.php at line 64 – humhub\modules\notes\libs\EtherpadLiteClient::__construct(null, 'api')
58596061626364656667686970

     */
    public static function getPadClient()
    {
        $module = Yii::$app->getModule('notes');
 
        if (!self::$_etherClient) {
            self::$_etherClient = new EtherpadLiteClient($module->settings->get('apiKey'), $module->settings->get('baseUrl') . "api");
        }
 
        return self::$_etherClient;
    }
 
    /**

3. in /var/www/html/humhub/protected/modules/notes/controllers/NoteController.php at line 90 – humhub\modules\notes\libs\EtherpadHelper::getPadClient()
84858687888990919293949596

        if (!$note->content->canView()) {
            throw new HttpException(401, 'Access denied!');
        }
 
        // SET ETHERPAD COOKIE
        $validUntil = mktime(0, 0, 0, date("m"), date("d") + 1, date("y")); // One day in the future
        $sessionID = EtherpadHelper::getPadClient()->createSession(EtherpadHelper::getPadGroupId($this->contentContainer), EtherpadHelper::getPadAuthorId(), $validUntil);
        $sessionID = $sessionID->sessionID;
 
        $domain = substr(yii\helpers\Url::base(''), 2);
        if (strpos($domain, '/') !== false) {
            $domain = substr($domain, 0, strpos($domain, '/'));
        }

4. humhub\modules\notes\controllers\NoteController::actionOpen()
5. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array([humhub\modules\notes\controllers\NoteController, 'actionOpen'], [])
6. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/Controller.php at line 181 – yii\base\InlineAction::runWithParams(['r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788f...'])
7. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/Module.php at line 534 – yii\base\Controller::runAction('open', ['r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788f...'])
8. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/web/Application.php at line 104 – yii\base\Module::runAction('notes/note/open', ['r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788f...'])
9. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/Application.php at line 392 – yii\web\Application::handleRequest(humhub\components\Request)
10. in /var/www/html/humhub/index.php at line 25 – yii\base\Application::run()
19202122232425

    require(__DIR__ . '/protected/humhub/config/web.php'),
    (is_readable(__DIR__ . '/protected/config/dynamic.php')) ? require(__DIR__ . '/protected/config/dynamic.php') : [],
    require(__DIR__ . '/protected/config/common.php'),
    require(__DIR__ . '/protected/config/web.php')
);
 
(new humhub\components\Application($config))->run();

$_GET = [ 'r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788ff1de', ];

$_COOKIE = [ 'PHPSESSID' => 'mc4bvid6p6silko9av3lijp3vn', '_csrf' => '4441ae3d5d3c8b42292c3722e637a96aab9310522dff6e59a9314a1d0d07e488a:2:{i:0;s:5:"_csrf";i:1;s:32:"9oTQgdVlZrmfpkVekuOSx7-fOhnpKKys";}', '_identity' => '37cfa49f254fcd7178511e3c3953f9afa42d5229f799f34b917ab5f109b796a9a:2:{i:0;s:9:"_identity";i:1;s:50:"[4,"6249f02a-f520-48ac-9b91-4830a75bfa14",2592000]";}', ];

$_SESSION = [ '__flash' => [], '__returnUrl' => 'http://sure.hcu-hamburg.de/', '__captcha/user/auth/captcha' => 'fnhpro', '__captcha/user/auth/captchacount' => 1, '__id' => 4, '__expire' => 1622628557, 'currentAuthClientId' => 'local', 'user.canSeeAdminSection' => true, 'live.poll.lastQueryTime' => 1622627122, ];

Can somebody help, please?

Ariel505 avatar Jun 02 '21 09:06 Ariel505

Hi, I also have similar issue. I enabled etherpad Note module in Space and can create a note. But when I want to edit it, it didn't work. The error message shows as follows: InvalidArgumentException [] is not a valid API key

1. in /var/www/html/humhub/protected/modules/notes/libs/EtherpadLiteClient.php at line 25
16171819202122232425262728293031323334

    const CODE_INVALID_FUNCTION = 3;
    const CODE_INVALID_API_KEY = 4;
 
    protected $apiKey = "";
    protected $baseUrl = "http://localhost:9001/api";
 
    public function __construct($apiKey, $baseUrl = null)
    {
        if (strlen($apiKey) < 1) {
            throw new InvalidArgumentException("[{$apiKey}] is not a valid API key");
        }
        $this->apiKey = $apiKey;
 
        if (isset($baseUrl)) {
            $this->baseUrl = $baseUrl;
        }
        if (!filter_var($this->baseUrl, FILTER_VALIDATE_URL)) {
            throw new InvalidArgumentException("[{$this->baseUrl}] is not a valid URL");
        }

2. in /var/www/html/humhub/protected/modules/notes/libs/EtherpadHelper.php at line 64 – humhub\modules\notes\libs\EtherpadLiteClient::__construct(null, 'api')
58596061626364656667686970

     */
    public static function getPadClient()
    {
        $module = Yii::$app->getModule('notes');
 
        if (!self::$_etherClient) {
            self::$_etherClient = new EtherpadLiteClient($module->settings->get('apiKey'), $module->settings->get('baseUrl') . "api");
        }
 
        return self::$_etherClient;
    }
 
    /**

3. in /var/www/html/humhub/protected/modules/notes/controllers/NoteController.php at line 90 – humhub\modules\notes\libs\EtherpadHelper::getPadClient()
84858687888990919293949596

        if (!$note->content->canView()) {
            throw new HttpException(401, 'Access denied!');
        }
 
        // SET ETHERPAD COOKIE
        $validUntil = mktime(0, 0, 0, date("m"), date("d") + 1, date("y")); // One day in the future
        $sessionID = EtherpadHelper::getPadClient()->createSession(EtherpadHelper::getPadGroupId($this->contentContainer), EtherpadHelper::getPadAuthorId(), $validUntil);
        $sessionID = $sessionID->sessionID;
 
        $domain = substr(yii\helpers\Url::base(''), 2);
        if (strpos($domain, '/') !== false) {
            $domain = substr($domain, 0, strpos($domain, '/'));
        }

4. humhub\modules\notes\controllers\NoteController::actionOpen()
5. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array([humhub\modules\notes\controllers\NoteController, 'actionOpen'], [])
6. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/Controller.php at line 181 – yii\base\InlineAction::runWithParams(['r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788f...'])
7. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/Module.php at line 534 – yii\base\Controller::runAction('open', ['r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788f...'])
8. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/web/Application.php at line 104 – yii\base\Module::runAction('notes/note/open', ['r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788f...'])
9. in /var/www/html/humhub/protected/vendor/yiisoft/yii2/base/Application.php at line 392 – yii\web\Application::handleRequest(humhub\components\Request)
10. in /var/www/html/humhub/index.php at line 25 – yii\base\Application::run()
19202122232425

    require(__DIR__ . '/protected/humhub/config/web.php'),
    (is_readable(__DIR__ . '/protected/config/dynamic.php')) ? require(__DIR__ . '/protected/config/dynamic.php') : [],
    require(__DIR__ . '/protected/config/common.php'),
    require(__DIR__ . '/protected/config/web.php')
);
 
(new humhub\components\Application($config))->run();

$_GET = [ 'r' => 'notes/note/open', 'id' => '2', 'cguid' => '000d6e0b-7cb5-4787-b66f-186d788ff1de', ];

$_COOKIE = [ 'PHPSESSID' => 'mc4bvid6p6silko9av3lijp3vn', '_csrf' => '4441ae3d5d3c8b42292c3722e637a96aab9310522dff6e59a9314a1d0d07e488a:2:{i:0;s:5:"_csrf";i:1;s:32:"9oTQgdVlZrmfpkVekuOSx7-fOhnpKKys";}', '_identity' => '37cfa49f254fcd7178511e3c3953f9afa42d5229f799f34b917ab5f109b796a9a:2:{i:0;s:9:"_identity";i:1;s:50:"[4,"6249f02a-f520-48ac-9b91-4830a75bfa14",2592000]";}', ];

$_SESSION = [ '__flash' => [], '__returnUrl' => 'http://sure.hcu-hamburg.de/', '__captcha/user/auth/captcha' => 'fnhpro', '__captcha/user/auth/captchacount' => 1, '__id' => 4, '__expire' => 1622628557, 'currentAuthClientId' => 'local', 'user.canSeeAdminSection' => true, 'live.poll.lastQueryTime' => 1622627122, ];

Can somebody help, please?

Assign Etherpad API from etherpad_root/APIKEY.txt to variable apiKey

initpwn avatar Oct 13 '21 20:10 initpwn