Posted by hh-gdo on December 19, 2008 at 4:33pm
I'm trying to access a Drupal service exposed by the SOAP api.
I'm using PHP with the SOAP extension in my client.
I keep getting "Token has expired." when I try and do user.login
1) I generated a key in Drupal admin and assigned it a domain.
2) I turned on use sessid (it was off) in the Drupal Services settings
3) below is the code I'm using:
PHP 5.2.6 with PHP SOAP extension...
.
.
$client = new SoapClient($this->config['wsdl_url'], array("trace"=>1, "exceptions"=>1));
// get a cookie for this session
$cookie = $this->getCookie($client);
$timeStamp = time();
$nonce = $this->getNonce(10);
$domain = 'myserver.com';//$this->config['domain'];
$func = 'user.login';
$hash = $this->getHMACHash($func, $domain, $apiKey, $timeStamp, $nonce);
$res = $client->__soapCall($func, array($hash,
$domain,
$timeStamp,
$nonce,
$cookie,
$username,
$password));
print_r($res);
// returns "Token has expired."
.
.
<snip>
.
.
/**
*
*
*/
private function getHMACHash($func, $domain, $apiKey, $timeStamp, $nonce)
{
// $message = implode(';', array($timeStamp, $domain, $nonce, $func)); // , $this->config['username'], $this->config['password']
$message = $timeStamp.';'.$domain.';'.$nonce.';'.$func;
return hash_hmac('sha256', $message, $apiKey);
}
private function getNonce($length)
{
$allowedCharacters = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$password = str_pad('', $length);
for ($i = 0; $i < $length; $i++)
{
$password[$i] = $allowedCharacters[rand(0, strlen($allowedCharacters) - 1)];
}
return $password;
}
private function getCookie($client)
{
$res = '';
try
{
//$objArr = $client->__soapCall('system.connect', array($this->config['api_key']));
$objArr = $client->__soapCall('system.connect', array());
if($objArr && is_array($objArr) && isset($objArr[0]))
{
$obj = $objArr[0];
if($obj->title == 'sessid')
$res = $obj->value;
}
}
catch (SoapFault $exception)
{
echo "SOAP: ".$exception;
}
return $res;
}any ideas??
Comments
try resetting expiring time
Hello,
I had the same. I have increased the time to expire to 60 seconds (though they weren't even nearly used up) and then it worked.
regards,
Philip
re: try resetting expiring time.
Yeah I tried increasing the expiry time but with no luck... thanks for the suggestion though!
SOAP Server & Client
Hello to all drupal developers. Firstly thumbs up for creating such a nice module. It is a great module with less documentation for example I am not able to find single help for creating Webservice as SOAP Client and SOAP Server. It is really a need for today scenario. If anybody know the link or have some knowledge please put all together here so that everybody can have access to that.
Sukh Singh
"Token has expired."
hello all,
I'm getting this "Token has expired." when doing subsequent calls.. has anyone found a solution/reason for this?
Check the time stamps on the
Check the time stamps on the servers - we've run into the same issue with expiration set to 60 seconds and it turned out the time difference on two servers was 80 seconds. Since we could not adjust the time settings we upped the expiration to 120 seconds.
Thank you for your quick
Thank you for your quick reply!
I tried upping the expiration in the Services settings but it didn't help..is that where I should do it?
Kind regards
Hi..Did you find any solution
Hi..Did you find any solution for this problem?As I am also getting the same error.And some time getting the error "Invalid API key"
Thanks
Swati, in my case, I was
Swati, in my case, I was calling two services at same time, with the same nounce and timestamp, so I changed my app to use a nounce of diferent size for each type of service.
Try do this, and post the results ;)
Parameters Order
Hi! Try to put a debug* in the services.module file, at function services_method_call (line 253).
In my tests I recieve the same error, "Token has expired.", I try too to increase the expiration time but the problem persists.
Looking beter I saw that my parameters order are wrong.
*My debug was put a mail function in this part of code, to send to me the values of timestap and time (I do the same at line 254, to see the full $args array())
line:292
$expiry_time = $timestamp + variable_get('services_key_expiry', 30);
if ($expiry_time < time()) {
return services_error(t('Token has expired.'));
}
I hope that's help you.
(Sory by the poor english).
Regards!
what value
what value $this->config['wsdl_url'] ?
what value url?
It is
http://drupal.tst/services/soap/wsdl
?
I solved the issue with Drupal "token has expired"
Just login to you Drupal Admin panel and go to following URL:
http://yourwebsite.com/admin/build/services/settings
On this page you will find and "Token expiry time: " setting. Change the value 30 to 180. that will solve the issue
Software Development