2009年3月17日星期二

Re: [fw-gdata] OAuth with Zend FW

Hi Peter,

Thanks much for the code snippet!
  Pádraic Brady is doing a Zend_Oauth component .  That's probably how we'll end up integrating OAuth into Zend_Gdata, but your solution is a great way in the meantime to allow Zend_Gdata developers to use OAuth.  Piadraic could use some help testing if you have a chance to help out.

Cheers,
-Ryan

On Thu, Mar 5, 2009 at 9:23 AM, Peter Kehl <peter.kehl@gmail.com> wrote:
I've made my Zend GData 1.7.3 installation work with OAuth
authorization, and I'd like to contribute it back to Zend. It's not
many changes - 2 member variables and setters/getters + 1
modification. I use http://oauth.googlecode.com/svn/code/php/OAuth.php
to get the OAuth-generated value of 'authorization' header - which is
under Apache2 license, so should be BSD-compatible - so we could have
a wrapper for it.

- Peter

Added to library/Zend/Gdata/HttpClient.php:

       /** Value of 'Authorization:' header
       */
       var $_oauthHeaderValue= null;
       /** Value of 'xoauth_requestor_id' HTTP parameter that we append to
the request URLs. Not url-encoded, since
               HttpClient will encode it itself.
       */
       var $_xoauthRequestorId= null;

       public function getOAuthHeaderValue() { return $this->_oauthHeaderValue; }
       public function setOAuthHeaderValue( $value ) {
$this->_oauthHeaderValue= $value; }

       public function getXoauthRequestorId() { return $this->xoauth_requestor_id; }
       public function setXoauthRequestorId( $value ) {
$this->xoauth_requestor_id= $value; }

Modified in library/Zend/Gdata/HttpClient.php:
   public function filterHttpRequest($method, $url, $headers =
array(), $body = null, $contentType = null) {
       if ($this->getAuthSubToken() != null) {
            // curent code...
       }
       } else
               if ($this->getClientLoginToken() != null) {
           $headers['authorization'] = 'GoogleLogin auth=' .
$this->getClientLoginToken();
       }
               elseif( $this->getOAuthHeaderValue() ) {
                       $headers['authorization']= $this->getOAuthHeaderValue();
               }
               if( $this->getXoauthRequestorId() ) {
                       $param_pair= 'xoauth_requestor_id=' .urlencode(
$this->getXoauthRequestorId() );
                       $separator= strpos($url, '?')===FALSE
                               ? '?'
                               : '&';
                       $url.= $separator.$param_pair;
               }
              // current code...

没有评论: