phplist-plugin-restapi icon indicating copy to clipboard operation
phplist-plugin-restapi copied to clipboard

Random failed authentication

Open avramovic opened this issue 8 years ago • 6 comments

Randomly the API fails to authenticate. It returns false and I have no idea what's causing this, but the code fails to add user to the list. Refresh of the page immediately "solves" the problem because then it works, but it's happening quite often and it's not acceptable for my client.

This is my code (from my own class constructor)

$this->api = new phpListRESTApiClient('http://www.xxxxx.com/mailer/admin/?page=call&pi=restapi', 'admin', 'xxxxxx', 'b2xxxxxxx9');
$connected = $this->api->login();
if (!$connected) {
  throw new RestApiException("Something is wrong with the phpList login!");
}

Is there any way to get more info about this issue? Is it known issue? Any ideas how to solve it?

avramovic avatar Mar 17 '16 23:03 avramovic

Problems like that are hard to debug. It could be connectivity issues, like DB or network. Best thing to do is to hack the code and add some logging in places and see how far it gets.

michield avatar Mar 20 '16 11:03 michield

Hi, I know this is a very old issue for a project which is essentially dead. But I had a similar issue with a newer version of a plugin and maybe my answer will help somebody somewhere. My issue was that the login to phplist failed for new sessions, but it succeeded for all subsequent sessions. This happened because the curl request sent a session cookie which already expired (from previous session) and phplist refused the login. So the fix was quite simple. You just have to add CURLOPT_COOKIESESSION to the curl request whenever you try to create a new session. It is best to extend the callApi function to accept a new parameter $newSession (true/false) and then use it like this curl_setopt($c, CURLOPT_COOKIESESSION, $newSession);

When you call it from login function, pass the $newSession parameter as true and when called from other functions, set it to default to false.

A link to the curl documentation: http://php.net/manual/en/function.curl-setopt.php

djaho avatar Dec 08 '18 09:12 djaho

Thanks for sharing. Do you plan to migrate to the new REST API (https://github.com/phpList/rest-API) at some stage?

samtuke avatar Dec 08 '18 10:12 samtuke

Thanks for your comment Sam. Right now, I am personally not planning on migrating to the new rest api, as the current one works good enough for me and I find it much easier to modify it for my purposes. And also, I think I had some issues (I don't remember what exactly) installing the new REST API to phplist (v3.3.5). And I remember that it was just a lot easier to install the old version of REST API ;)

djaho avatar Dec 08 '18 12:12 djaho

@djaho OK, even though the REST API that you're using is no longer maintained, we would welcome pull requests with the improvements that you've made.

A new version of phpList will be released shortly which includes an automatic updater. In future releases that updater will allow installing the new REST API also, which should make it easier for you to set it up and try it out.

samtuke avatar Dec 08 '18 17:12 samtuke

@samtuke I will test my change for some more time and if all will be well, I will make a pull request. Even though this will be my fist Github pull request :)

Thanks for the info about the updater. I will definitely check the new rest api.

djaho avatar Dec 08 '18 18:12 djaho