Hello Anirudh,

Thanks for trying the perl version of the authentication.

Your version of ProxyWithCurl has a function not found in the version
I found: connectHandShake.  Bottom line, the api retrieveAllUsers is
now working!  Thank you so much for you help.

Larry

On Jul 1, 8:31 am, "Anirudh (Google)" <[EMAIL PROTECTED]> wrote:
> Hi Larry,
>
> Thanks for your patience with this issue.
> I tried running the PHP code shared earlier by you along with Ryan's
> 'ProxyWithCurl' Adapter on my GoDaddy hosting test account and was
> able to successfully authenticate and retrieve my Google Apps user
> accounts.
> I have a deluxe hosting account with GoDaddy with Hosting Config
> v2.0 . They do seem to have different hosting configurations for
> accounts.
>
> Here is the PHP code that worked with 'ProxyWithCurl' Adapter for
> ZendGData-1.5.2:
>
> <?php
>
> $path = './Zend';
> set_include_path(get_include_path() . PATH_SEPARATOR . $path);
> $path = get_include_path();
> echo "$path";
>
> require_once "Zend/Http/Client/Adapter/ProxyWithCurl.php";
> require_once "Zend/Loader.php";
> Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
> Zend_Loader::loadClass('Zend_Gdata_Gapps');
>
> $email = "[EMAIL PROTECTED]";
> $password = "password";
> $domain = "example.com";
>
>  $service = Zend_Gdata_Gapps::AUTH_SERVICE_NAME;
>
> $config = array(
>                 'adapter'    =>
> 'Zend_Http_Client_Adapter_ProxyWithCurl',
>                 'proxy_host' => 'proxy.shr.secureserver.net',
>                 'proxy_port' => 3128
>                );
> // Instantiate a client object
> $clientp = new Zend_Http_Client();
> $clientp->setConfig($config);
>
> $client = Zend_Gdata_ClientLogin::getHttpClient($email, $password,
> $service,$clientp);
> echo "connected";
> $service = new Zend_Gdata_Gapps($client, $domain);
> $feed = $service->retrieveAllUsers();
> $html = true;
>
>    if ($html) {echo "<h2>Registered Users</h2>\n";}
>
>     if ($html) {echo "<ul>\n";}
>
>     foreach ($feed as $user) {
>         if ($html) {
>             echo "  <li>";
>         } else {
>             echo "  * ";
>         }
>         echo $user->login->username . ' (';
>         if ($html) {
>             echo htmlspecialchars($user->name->givenName . ' ' .
>                 $user->name->familyName);
>         } else {
>             echo $user->name->givenName . ' ' . $user->name->familyName;
>
>         }
>         echo ')';
>         if ($html) {echo '</li>';}
>         echo "\n";
>     }
>     if ($html) {echo "</ul>\n";}
>
> I am also appending the 'ProxyWithCurl' Adapter for your reference:
>
> class Zend_Http_Client_Adapter_ProxyWithCurl extends
> Zend_Http_Client_Adapter_Socket
> {
>
>     protected $config = array(
>         'ssltransport'  => 'ssl',
>         'proxy_host'    => '',
>         'proxy_port'    => 8080,
>         'proxy_user'    => '',
>         'proxy_pass'    => '',
>         'proxy_auth'    => Zend_Http_Client::AUTH_BASIC
>     );
>
>      public function connect($host, $port = 80, $secure = false)
>             {
>                 // If no proxy is set, fall back to Socket adapter
>                 if (! $this->config['proxy_host']) {
>                     return parent::connect($host, $port, $secure);
>                 }
>             }
>             public function write($method, $uri, $http_ver = '1.1', $headers
> =       array(), $body = '')
>             {
>                 // If no proxy is set, fall back to default Socket adapter
>                 if (! $this->config['proxy_host']) {
>                     return parent::write($method, $uri, $http_ver, $headers,
> $body);
>                 }
>
>                 $host = $this->config['proxy_host'];
>                 $port = $this->config['proxy_port'];
>
>                 $ch = curl_init();
>                 curl_setopt($ch, CURLOPT_VERBOSE, 0);
>                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>                 curl_setopt($ch, CURLOPT_HEADER, true);
>                 curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
>                 curl_setopt($ch, CURLOPT_PROXY,"http://"; . $host . ':' .
> $port);
>                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
>                 curl_setopt($ch, CURLOPT_URL, $uri->__toString());
>                 curl_setopt($ch, CURLOPT_TIMEOUT, 120);
>
>                 // Save request method for later
>                 $this->method = $method;
>
>                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
>
>                 // Add Proxy-Authorization header
>                 if ($this->config['proxy_user'] && ! isset($headers['proxy-
> authorization'])) {
>                     $headers['proxy-authorization'] =
> Zend_Http_Client::encodeAuthHeader(
>                         $this->config['proxy_user'], $this-
>
> >config['proxy_pass'], $this->config['proxy_auth']
>
>                     );
>                 }
>
>                 $curlHeaders = array();
>
>                 // Add all headers to the curl header array
>                 foreach ($headers as $k => $v) {
>                     if (is_string($k)) $v = ucfirst($k) . ": $v";
>                     $curlHeaders[] = $v;
>                 }
>                 curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);
>
>                 if ($body != null) {
>                     curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
>                 }
>
>                 $this->result = curl_exec($ch);
>                 // HACK- The server returns chunked transfer encoding at
> times, and it's indicated in the header
>                 // However, curl and ZF both attempt to decode, leading to
> exceptions being thrown
>                 // There has to be a way to avoid the following line (o
> something like it), but haven't figured it out yet
>                 $this->result = str_ireplace('Transfer-encoding:', 'Transfer-
> encoding-old:', $this->result);
>                 return $this->result;
>             }
>
>             public function read()
>             {
>                 return $this->result;
>              }
>
>     /**
>      * Preform handshaking with HTTPS proxy using CONNECT method
>      *
>      * @param string  $host
>      * @param integer $port
>      * @param string  $http_ver
>      * @param array   $headers
>      */
>     protected function connectHandshake($host, $port = 443, $http_ver
> = '1.1', array &$headers = array())
>     {
>         $request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
>                    "Host: " . $this->config['proxy_host'] . "\r\n";
>
>         // Add the user-agent header
>         if (isset($this->config['useragent'])) {
>                 $request .= "User-agent: " . $this->config['useragent'] . "\r
> \n";
>         }
>
>         // If the proxy-authorization header is set, send it to proxy but
> remove
>         // it from headers sent to target host
>         if (isset($headers['proxy-authorization'])) {
>             $request .= "Proxy-authorization: " . $headers['proxy-
> authorization'] . "\r\n";
>             unset($headers['proxy-authorization']);
>         }
>
>         $request .= "\r\n";
>
>         // Send the request
>         if (! @fwrite($this->socket, $request)) {
>             require_once 'Zend/Http/Client/Adapter/Exception.php';
>             throw new Zend_Http_Client_Adapter_Exception("Error
> writing request to proxy server");
>         }
>
>         // Read response headers only
>         $response = '';
>         $gotStatus = false;
>         while ($line = @fgets($this->socket)) {
>             $gotStatus = $gotStatus || (strpos($line, 'HTTP') !==
> false);
>             if ($gotStatus) {
>                 $response .= $line;
>                 if (!chop($line)) break;
>             }
>         }
>
>         // Check that the response from the proxy is 200
>         if (Zend_Http_Response::extractCode($response) != 200) {
>                 require_once 'Zend/Http/Client/Adapter/Exception.php';
>                 throw new Zend_Http_Client_Adapter_Exception("Unable to
> connect to HTTPS proxy. Server response: " . $response);
>         }
>
>         // If all is good, switch socket to secure mode. We have to
> fall back
>         // through the different modes
>         $modes = array(
>             STREAM_CRYPTO_METHOD_TLS_CLIENT,
>             STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
>             STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
>             STREAM_CRYPTO_METHOD_SSLv2_CLIENT
>         );
>
>         $success = false;
>         foreach($modes as $mode) {
>             $success = stream_socket_enable_crypto($this->socket,
> true, $mode);
>                 if ($success) break;
>         }
>
>         if (! $success) {
>                 require_once 'Zend/Http/Client/Adapter/Exception.php';
>                 throw new Zend_Http_Client_Adapter_Exception("Unable to
> connect to" .
>                     " HTTPS server through proxy: could not negotiate secure
> connection.");
>         }
>     }
>
>     /**
>      * Close the connection to the server
>      *
>      */
>     public function close()
>     {
>         parent::close();
>         $this->negotiated = false;
>     }
>
>     /**
>      * Destructor: make sure the socket is disconnected
>      *
>      */
>     public function __destruct()
>     {
>         if ($this->socket) $this->close();
>     }
>
> }
>
> I did try the Perl script and faced the same error as you from
> GoDaddy. It looks like it needs the same workaround i.e. proxy server
> for SSL.
> GoDaddy doesn't seem to have any information in their Help Center for
> Perl+SSL as they do for PHP.
> I will investigate on this further.
>
> -Anirudh
>
> On Jul 1, 2:33 pm,techlover<[EMAIL PROTECTED]> wrote:
>
> > Hello Anirudth,
>
> > Thank you for you suggestions. I setup Wireshark and tried it using
> > the following code straight from the GApps help pages (no special mods
> > made):http://code.google.com/apis/apps/google_apps_provisioning_api_v1.0_re....
>
> >  I would appreciate your repeating this simple experiment.  From what
> > I have read in this forum and experienced on my own, GoDaddy and
> > Google servers are not playing together well.
>
> > The perl script shown was uploaded and run on two different GoDaddy
> > hosted accounts of mine (both happen to be registered with GApps).  I
> > tried all 3 of my GPapps Education accounts where APIs were activated
> > via the GApps Control Panel.  I was very careful to use the correct
> > parameters including Email (of an admin) and his password. In each
> > case no output ever occurred.  The GoDaddy error logs showed a timeout
> > (at the $lwp_object->post call). "https://www.google.com/accounts/
> > ClientLogin error: 500 Connect failed: connect: Connection timed out;
> > Connection timed out at /home/content/a/b/c/abcadmin/html/cgi/
> > auth_token.pl line 25."
>
> > BTW, last week I formally submitted this issue as a trouble ticket
> > using the Education credentials for one of my Education accounts.  I
> > received a message
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Apps APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to