kicsyromy Posted July 2, 2011 Report Share Posted July 2, 2011 I'm having some problems with the token authentication if uTorrent WebUI. I'm trying to make a client connect to the server and get the list of torrents from it. I retrieve a token from the server successfully but when trying to retrieve anything else using that token the server returns an invalid request error. So my question is how long is the token valid? how does the server know which tokens are valid and which not, if i connect from multiple clients do i need multiple tokens?Thx in advance for any info provided,Romeo Calota Link to comment Share on other sites More sharing options...
DreadWingKnight Posted July 2, 2011 Report Share Posted July 2, 2011 Have you tried retrieving the token from the token.html?Each token is only valid for one client. Link to comment Share on other sites More sharing options...
kicsyromy Posted July 2, 2011 Author Report Share Posted July 2, 2011 Yes, I get the token from /gui/token.html, I store it and append it to every query i make to the server (i.e. /gui/?list=1&token=<the_stored_token>)P.S. I've just realized something, does the GUID have anything to do with the token? do i need to store and include that in the request together with the token?YES! That was the problem. The cookie needs to be included in the HTTP request header. Link to comment Share on other sites More sharing options...
lithopsian Posted July 3, 2011 Report Share Posted July 3, 2011 Sounds like you solved it. Got to send back the cookie with each request. Most software will do this automatically.The token is valid forever, or at least for the length of that session. It lasts for 30 minutes across different sessions., I think. Still, you should probably code for the situation where another token needs to be fetched. Link to comment Share on other sites More sharing options...
kzahel Posted October 21, 2011 Report Share Posted October 21, 2011 Sorry you had to figure this out. It seems the documentation is a little out of date. Link to comment Share on other sites More sharing options...
agnivohneb Posted November 1, 2011 Report Share Posted November 1, 2011 I seem to be having a problem with my authentication. I want to display a list of the torrents but having a problem getting past the token.I see @kicsyromy got it to work but I don't know what he is talking about when he says GUID.And I don't know if cURL will keep cookies and send them back.It appears that the last request made to get the list is getting back the invalid request message from uTorrent.Can someone have a look at my code and tell me if I am even doing this right. I have been working on this all night and getting very frustrated with it. Thanks.<?phpclass uTorrentAPI{ public $conf_user = "test"; public $conf_pass = "test"; public $conf_host = "localhost:8086"; public $token = NULL; public $crl = NULL; function __construct() { $this->crl = curl_init(); $this->token = $this->get_token (); } function __destruct() { curl_close($this->crl); } public function load_data($action, $load_token = true){ if (isset($action)) { if ($load_token) { return $this->get_url_contents("http://" . $this->conf_user . ":" . $this->conf_pass . "@" . $this->conf_host . "/gui/?token=" . $this->token . $action); } else { return $this->get_url_contents("http://" . $this->conf_user . ":" . $this->conf_pass . "@" . $this->conf_host . "/gui/" . $action); } } } public function get_url_contents($url) { $timeout = 5; curl_setopt ($this->crl, CURLOPT_URL,$url); curl_setopt ($this->crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($this->crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($this->crl); return $ret; } public function get_token () { return strip_tags($this->load_data("token.html", false)); } public function get_torrent_list() { return json_decode($this->load_data("&list=1"),true); }}$api = new uTorrentAPI();echo $api->token;var_dump($api->get_torrent_list()); // Returns NULL?> Link to comment Share on other sites More sharing options...
agnivohneb Posted November 1, 2011 Report Share Posted November 1, 2011 OK I got it now... I had a good sleep and got at it with a fresh mind and got it to work .I used some code from http://forum.utorrent.com/viewtopic.php?pid=545126#p545126 and changed the get_url_contents function and its working fine.This is the new function inside the uTorrentAPI class public function get_url_contents($url) { $curl_opts=Array( CURLOPT_FRESH_CONNECT => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_COOKIEFILE => 'cookiejar.tmp', CURLOPT_COOKIEJAR => 'cookiejar.tmp', CURLOPT_CONNECTTIMEOUT => 5 ); curl_setopt_array($this->crl, $curl_opts); $ret = curl_exec($this->crl); return $ret; } Link to comment Share on other sites More sharing options...
hunter1 Posted November 9, 2011 Report Share Posted November 9, 2011 Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /var/www/clients/client2/web214/web/ctest.phpsafe_mode is offit is possible dont use CURLOPT_FOLLOWLOCATION in curl? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.