Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Pear::soap

  1. #11
    miglius is offline Starter Member
    Join Date
    Oct 2007
    Posts
    1
    Rep Power
    7

    Default

    I did actually get this working, and have the PEAR::SOAP module working nicely; happily I can probably answer any questions that anyone has regarding using this module with zimbra.

    Can you, please, share how you send back the authToken to the zimbra using pear::soap? How do you construct a header? I tried several ways with no success....

  2. #12
    zenthanian is offline Junior Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    7

    Default PreAuth in PHP

    This is code that I found elsewhere....

    To get the Preauth Token....
    Code:
    include_once 'Message/Message.php';
    
    $nowTime = time();
    $fixedTime = $nowTime * 1000;
    $key = '[from zmprov]';
    
    $user = "[username]";
    
    $toString = $user."|name|0|".$fixedTime;
    
    $hmac = Message::createHMAC('SHA1',$key);
    
    $sig_sha1 = $hmac->calc($toString);
    
    $client = new SoapClient(null,
    	array(
    		'location' => "http://server.com/service/soap/",
    		'uri' => "urn:zimbraAccount",
    		'trace' => 1,
    		'exceptions' => 1,
    		'soap_version' => SOAP_1_2,
    		'style' => SOAP_RPC,
    		'use' => SOAP_LITERAL
    	)
    );
    echo "Client Built<br>";
    
    $params = array(
    		new SoapParam($casUser, "account"),
    		new SoapVar('<preauth timestamp="' . $fixedTime . '" expires="0">' . $sig_sha1 . '</preauth>', XSD_ANYXML)
    		);
    echo "Params built<br>";
    
    try {
    	echo "creating header<br>";
    	$soapHeader = new SoapHeader(
    				'urn:zimbraAccount',
    				'context'
    				);
    
    	echo "trying<br>";
    	$result = $client->__soapCall(
    				"AuthRequest",
    				$params,
    				null,
    				$soapHeader
    	);
            echo "executed<br>";
    } catch (SoapFault $exception) {
            echo "exception caught 51<br><br>";
            echo $client->__getLastRequest() . "<br><br>";
            echo $client->__getLastRequestHeaders() . "<br><br>";
            echo $client->__getLastResponseHeaders() . "<br><br>";
            echo $client->__getLastResponse() . "<br><br>";
            echo $exception . "<br><br>";
    }
    
    echo "done<br><br>";
    $authToken=$result['authToken'];

    To use the token, create SoapHeader and pass it as the fifth argument of the __soapCall...
    Code:
    $soapHeader = new SoapHeader(
                        'urn:zimbra',
                        'context',
                        new SoapVar('<ns2:context><authToken>' . $authToken . '</authToken></ns2:context>', XSD_ANYXML)
                        );
    I did actually get this working, and have the PEAR::SOAP module working nicely
    Mind sharing your code?

  3. #13
    Ericx is offline Loyal Member
    Join Date
    Jul 2006
    Location
    Virginia Beach, VA
    Posts
    97
    Rep Power
    9

    Default php preauthentication

    Here is some code using php5 to help generate the preauth token. It is working for me, I hopes it help someone else also.

    This code is part of the Zimlet email class I'm building into pepperPM; a sourceforge project.


    PHP Code:
        function do_zimbra_preauth_token_math_debug($toString,$zm_key,$pepperpm_timestamp,$hmac){
            
    $tmp_str "";
            
    $tmp_str "To test this ssh into your zimbra box";
            
    $tmp_str .= "<br/>";
            
    $tmp_str .= " su zimbra";
            
    $tmp_str .= "<br/>";
            
    $tmp_str .= "zmprov (press enter)";
            
    $tmp_str .= "<br/>";
            
    $tmp_str .= "gdpa example.com user@example.com name ".$pepperpm_timestamp." 0";
            
    $tmp_str .= "<br/>";
            
    $tmp_str .= "compare the output with the text below!";
            
    $tmp_str .= "<br/>";
            
    $tmp_str .= $hmac;
            return (
    $tmp_str);
        }
        
        function 
    do_zimbra_preauth_token_math($zm_account$zm_type $zm_expires){
            
    $zm_key ""//put your key here that you generated from the zimbra server
            
    $nowTime time();
            
    $pepperpm_timestamp $nowTime 1000;
            
    $toString $zm_account."|".$zm_type."|".$zm_expires."|".$pepperpm_timestamp;
            
    $hmac =  hash_hmac('sha1',$toString,$zm_key,false);
            
    //echo $this->do_zimbra_preauth_token_math_debug($toString,$zm_key,$pepperpm_timestamp,$hmac);
            
    return ($hmac);
        }
        

    // Start here, you will need to follow the code and change some stuff, I replaced my variables with example.com 
        
    function get_zimbra_preauth_token(){
            
    $zm_account user@example.com
            
    $zm_type "name"// use ID if you are using zimbra ID, there are other options see the preauth.txt in the zimbra source.
            
    $zm_expires "0" //0 or some number to set when it expires
            
    $zm_preauth_token $this->do_zimbra_preauth_token_math($zm_account$zm_type $zm_expires);    
            return (
    $zm_preauth_token);
        } 
    EricX

  4. #14
    chapman_164 is offline Active Member
    Join Date
    Jan 2008
    Posts
    28
    Rep Power
    7

    Default

    I've been beating my head against this and just can't make it work. I'm able to authenticate using AuthRequest in both Pear::Soap and php5's built-in soap client and am able to pass the authToken back. What I can't figure out is how to get call a method that has attributes (such as SearchRequest). Is there a way to do this in PHP without intercepting and rewriting the soap request?

    Thanks,
    Mike Chapman

  5. #15
    ljm
    ljm is offline Project Contributor
    Join Date
    May 2006
    Posts
    81
    Rep Power
    9

    Default

    > What I can't figure out is how to get call a method that has
    > attributes (such as SearchRequest). Is there a way to do
    > this in PHP without intercepting and rewriting the soap request?

    You have to intercept, rewrite the request XML and parse the response XML.

    One thing that's good to understand about the Zimbra SOAP API is that it's a Document-style API, not an RPC-style API that many developers are familiar with.

    I think this is the underlying reason why the SOAP convenience conversions in PHP5 and PEAR:SOAP aren't much use - because they are oriented towards RPC-style APIs.

    So the upshot is - you're stuck working with XML. Once the basic infrastructure pieces are in place it's not so bad. Figure an extra day or two on your dev timeline...
    Zindus - contact sync for Thunderbird and Zimbra

  6. #16
    chapman_164 is offline Active Member
    Join Date
    Jan 2008
    Posts
    28
    Rep Power
    7

    Default

    Quote Originally Posted by ljm View Post
    You have to intercept, rewrite the request XML and parse the response XML.
    Thanks for the help. I was hoping there was an easy fix but I guess that's not the case most of the time. Looks like I need to start digging into XML.

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •