AnsweredAssumed Answered

Calling an Alfresco Webservice from PHP.

Question asked by kasperba on Apr 5, 2008
Hey guys,

I'v been trying to figure out how to call Alfresco from PHP - and i found a nice little way:

   // Perform to Get Order Info call to alfresco.
   $query_string = "";

   $params = array( 'email' => $RA_USER_EMAIL ,
              'nationcode'  => $cb_customer_national,
              'customerrefno'  => $cb_easycollect_uid,
   );

   foreach ($params as $key => $value) {
          $query_string .= "$key=" . urlencode($value) . "&";
   }

   $url = "$order_base?$query_string";

   $output = file_get_contents($url);

   $stringData = "setclickandbuycustomerrefno REST Call result: $output\r\n";
   fwrite($fh, $stringData);

Works great and all…. but…. How do i do this when i want to contact a service where authentication is set to true?  

<webscript>
  <shortname>setclickandbuycustomerrefno</shortname>
  <description>Set Click-and-Buy Customer Ref No</description>
  <url>/person/setclickandbuycustomerrefno?email={email}&amp;customerrefno={customerrefno}&amp;nationcode={nationcode}</url>
  <format default="xml"/>
  <authentication>true</authentication>
  <transaction>required</transaction>
</webscript>

Please note that the PHP script is beeing executed on a XAMPP installation (Apache Extension), and is beeing called when an EasyCollect goes through in out current Payment system (ClickAndBuy).

The script has the users TICKET as a parameter - thats not an issue - this is beeing transfered from ClickAndBuy to this PHP script as a parameter.

So the real question would be:

[size=150]How do i call an Authentication Enabled Alfresco Webservice with PHP, using only a TICKET as authentication?[/size]

Used a couple of days to research it and found this so far:

As far as i can tell it should be possible to manipulate the header to contain the ticket - or is just adding the ticket as a parameter ?

https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/source/java/org/alfresco/repo/webdav/auth/AuthenticationFilter.java

Looking at the fitler it seams alfresco is looking for a ARG-TICKET parameter to figure out if the user can be authorized.
If indeed i have to put it into the header of the call, then it seams to be pretty tricky.

In this article a developer is actually doing this - calling Alfresco from PHP, setting the username, password and authentication method in the header:

http://joseph.randomnetworks.com/archives/2007/09/19/http-basic-authentication-a-tale-of-atompub-wordpress-php-apache-cgi-and-ssltls/

He states:

"When running as a server module (mod_php) PHP takes care of decoding HTTP basic for you (see HTTP basic authentication in PHP). When a using HTTP basic PHP will automatically populate $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] variables with the username and password that were provided. IF and ONLY IF PHP is being run as a server module (like mod_php). If you are running PHP as a CGI then those two variables won’t get created at all, ever, even when using HTTP basic authentication".

As im using XAMPP im sure its a php module running on the apache underneath.

So maybe its the actual PHP documentation i should be looking at: http://us3.php.net/features.http-auth

It explains a few methods of doing a username + password authentication, but nothing about doing the authentication with a ticket….. which is all i have.

Also i sniffed up clues about using curl_file_get_contents - which is avaiable in the curl lib for PHP - it has a bit more settings for making GET and POST calls - ill look into that.

Other than that Im pretty stuck here - i really hope someone in this forum knows some answers which could help me.

//Kasper

Outcomes