Hadn't found any info on the below code and recently figured it out.
Just to add to the database of info on these forums; here is how to auth to Zimbra as a standard user (as opposed to an Admin) in PHP using the built-in SOAP extensions:
$soapurl = The non-admin (/service/soap/) URL of your server
$authoken = An authToken returned from a urn:zimbraAdmin call to DelegateAuthRequest
$context = zimbraMail, zimbra, etc.
$user = a valid zimbra user ID (ie: b5e0355-3b57-41a9-a131-2e.....)
$session = A valid sessionID from the DelegateAuthRequest request
Unfortunately, PHP's SOAP extension doesn't allow attributes in tags, so it's rather messy:
Code:
function zimbraSOAPUserLogin($soapurl,$user,$authtoken,$session,$context) {
$client = new SoapClient(null, array('location' => $soapurl, 'uri' => "urn:" . $context, 'trace' => 1, 'exceptions' => 1, 'soap_version' => SOAP_1_1, 'style' => SOAP_RPC, 'use' => SOAP_LITERAL));
$soapHeader = array(new SoapHeader('urn:zimbra','context xmlns="urn:zimbra"',new SoapVar('<ns2:context><authToken>' . $authtoken . '</authToken><sessionId id="' . $session . '"/><account by="id">'. $user .'</account></ns2:context>',XSD_ANYXML)));
$client->__setSoapHeaders($soapHeader);
return $client;
}