You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2009/05/10 21:38:47 UTC

svn commit: r773391 - in /incubator/shindig/trunk/php/src: common/RemoteContentRequest.php common/sample/BasicRemoteContent.php gadgets/ProxyBase.php gadgets/oauth/OAuthFetcher.php gadgets/oauth/OAuthFetcherFactory.php gadgets/oauth/OAuthRequestParams.php

Author: chabotc
Date: Sun May 10 19:38:47 2009
New Revision: 773391

URL: http://svn.apache.org/viewvc?rev=773391&view=rev
Log:
SHINDIG-1041 by Pan Jie - Adds support for OAuth params to the OAuthFetcher

Modified:
    incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
    incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
    incubator/shindig/trunk/php/src/gadgets/ProxyBase.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php

Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=773391&r1=773390&r2=773391&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Sun May 10 19:38:47 2009
@@ -62,6 +62,11 @@
    * @var string
    */
   private $authType;
+  
+  /**
+   * @var OAuthRequestParams
+   */
+  private $oauthParams = null;
 
   public function __construct($uri, $headers = false, $postBody = false) {
     $this->uri = $uri;
@@ -285,6 +290,17 @@
   public function getToken() {
     return $this->token;
   }
+  
+  public function setOAuthRequestParams(OAuthRequestParams $params) {
+    $this->oauthParams = $params;
+  }
+  
+  /**
+   * @return OAuthRequestParams
+   */
+  public function getOAuthRequestParams() {
+    return $this->oauthParams;
+  }
 
   /**
    * Sets the authorization type for this request, can be one of

Modified: incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php?rev=773391&r1=773390&r2=773391&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php (original)
+++ incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php Sun May 10 19:38:47 2009
@@ -189,7 +189,7 @@
         $fetcher = $this->signingFetcherFactory->getSigningFetcher($this->basicFetcher);
         return $fetcher->fetchRequest($request);
       case RemoteContentRequest::$AUTH_OAUTH:
-        $params = new OAuthRequestParams();
+        $params = $request->getOAuthRequestParams();
         $token = $request->getToken();
         $fetcher = $this->signingFetcherFactory->getSigningFetcher($this->basicFetcher);
         $oAuthFetcherFactory = new OAuthFetcherFactory($fetcher);

Modified: incubator/shindig/trunk/php/src/gadgets/ProxyBase.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyBase.php?rev=773391&r1=773390&r2=773391&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyBase.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyBase.php Sun May 10 19:38:47 2009
@@ -89,6 +89,7 @@
           break;
         case 'OAUTH':
           $request->setAuthType(RemoteContentRequest::$AUTH_OAUTH);
+          $request->setOAuthRequestParams(new OAuthRequestParams($_POST));
           break;
       }
       $token = $this->context->extractAndValidateToken($signer);

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php?rev=773391&r1=773390&r2=773391&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php Sun May 10 19:38:47 2009
@@ -62,7 +62,8 @@
   protected $authToken;
 
   /**
-   * Parameters from makeRequest
+   * Parameters from makeRequest
+   * @var OAuthRequestParams
    */
   protected $requestParams;
 
@@ -146,7 +147,7 @@
       try {
         $this->origClientState = $this->oauthCrypter->unwrap($origClientState, self::$CLIENT_STATE_MAX_AGE_SECS);
       } catch (BlobCrypterException $e) {// Probably too old, pretend we never saw it at all.
-      }
+}
     }
     if ($this->origClientState == null) {
       $this->origClientState = array();
@@ -198,9 +199,9 @@
       $accessor->tokenSecret = $this->origClientState[self::$ACCESS_TOKEN_SECRET_KEY];
     } else if ($accessor->accessToken == null && $this->requestParams->getRequestToken() != null) {
       // We don't have an access token yet, but the client sent us a
-      // (hopefully) preapproved request token.
-      $accessor->requestToken = $requestParams->getRequestToken();
-      $accessor->tokenSecret = $requestParams->getRequestTokenSecret();
+      // (hopefully) preapproved request token.
+      $accessor->requestToken = $this->requestParams->getRequestToken();
+      $accessor->tokenSecret = $this->requestParams->getRequestTokenSecret();
     }
   }
 
@@ -279,13 +280,13 @@
     $pageOwner = $this->authToken->getOwnerId();
     $pageViewer = $this->authToken->getViewerId();
     $stateOwner = @$this->origClientState[self::$OWNER_KEY];
-    if (!$pageOwner) {
+    if (! $pageOwner) {
       throw new GadgetException('Unauthenticated');
     }
     if ($pageOwner != $pageViewer) {
       throw new GadgetException("Only page owners can grant OAuth approval");
     }
-    if ($stateOwner != null && !$stateOwner == $pageOwner) {
+    if ($stateOwner != null && ! $stateOwner == $pageOwner) {
       throw new GadgetException("Client state belongs to a different person.");
     }
   }
@@ -454,7 +455,7 @@
     $accessor = $this->accessorInfo->getAccessor();
     $azn = $accessor->consumer->callback_url->userAuthorizationURL;
     $authUrl = $azn->url;
-    if (strstr($authUrl, "?") == FALSE ) {
+    if (strstr($authUrl, "?") == FALSE) {
       $authUrl .= "?";
     } else {
       $authUrl .= "&";
@@ -534,7 +535,7 @@
       $rcr = $this->createRemoteContentRequest($this->filterOAuthParams($oauthRequest), $this->realRequest->getMethod(), $this->realRequest->getUrl(), $this->realRequest->getHeaders(), $this->realRequest->getContentType(), $this->realRequest->getPostBody(), $this->realRequest->getOptions());
       //TODO is there a better way to detect an SP error?
       $fetcher = new BasicRemoteContentFetcher();
-      $content = $fetcher->fetchRequest($rcr);
+      $content = $fetcher->fetchRequest($rcr);
       $statusCode = $content->getHttpCode();
       if ($statusCode >= 400 && $statusCode < 500) {
         $message = $this->parseAuthHeader(null, $content);
@@ -543,7 +544,7 @@
         }
       }
       // Track metadata on the response
-      $this->addResponseMetadata($content);
+      $this->addResponseMetadata($content);
       return $content;
     } catch (Exception $e) {
       throw new GadgetException("INTERNAL SERVER ERROR: " . $e);
@@ -623,16 +624,16 @@
     }
   }
 
-  public function multiFetchRequest(Array $requests) {  // Do nothing
-  }
-  
-  private static function addIdentityParams(array& $params, SecurityToken $token) {
+  public function multiFetchRequest(Array $requests) {// Do nothing
+}
+
+  private static function addIdentityParams(array & $params, SecurityToken $token) {
     $params['opensocial_owner_id'] = $token->getOwnerId();
     $params['opensocial_viewer_id'] = $token->getViewerId();
     $params['opensocial_app_id'] = $token->getAppId();
     $params['opensocial_app_url'] = $token->getAppUrl();
   }
-  
+
   private static function setStrictNoCache(RemoteContentRequest $response) {
     $response->setResponseHeader('Pragma', 'no-cache');
     $response->setResponseHeader('Cache-Control', 'no-cache');

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php?rev=773391&r1=773390&r2=773391&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php Sun May 10 19:38:47 2009
@@ -75,7 +75,7 @@
    * @return The oauth fetcher.
    * @throws GadgetException
    */
-  public function getOAuthFetcher($fetcher, $token, $params) {
+  public function getOAuthFetcher(RemoteContentFetcher $fetcher, SecurityToken $token, OAuthRequestParams $params) {
     return new OAuthFetcher($this->tokenStore, $this->oauthCrypter, $fetcher, $token, $params);
   }
 }

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php?rev=773391&r1=773390&r2=773391&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php Sun May 10 19:38:47 2009
@@ -35,24 +35,21 @@
   protected $origClientState;
   protected $bypassSpecCache;
 
-  public function __construct() {
-    $this->serviceName = $this->getParam(self::$SERVICE_PARAM, "");
-    $this->tokenName = $this->getParam(self::$TOKEN_PARAM, "");
-    $this->requestToken = $this->getParam(self::$REQUEST_TOKEN_PARAM, null);
-    $this->requestTokenSecret = $this->getParam(self::$REQUEST_TOKEN_SECRET_PARAM, null);
-    $this->origClientState = $this->getParam(self::$CLIENT_STATE_PARAM, null);
-    $this->bypassSpecCache = $this->parseBypassSpecCacheParam();
+  public function __construct(array $arguments) {
+    $this->serviceName = self::getParam($arguments, self::$SERVICE_PARAM, "");
+    $this->tokenName = self::getParam($arguments, self::$TOKEN_PARAM, "");
+    $this->requestToken = self::getParam($arguments, self::$REQUEST_TOKEN_PARAM, null);
+    $this->requestTokenSecret = self::getParam($arguments, self::$REQUEST_TOKEN_SECRET_PARAM, null);
+    $this->origClientState = self::getParam($arguments, self::$CLIENT_STATE_PARAM, null);
+    $this->bypassSpecCache = '1' == self::getParam($arguments, self::$BYPASS_SPEC_CACHE_PARAM, null);
   }
 
-  private function getParam($name, $def) {
-    $val = null;
-    if (isset($_REQUEST[$name])) {
-      $val = $_REQUEST[$name];
+  private static function getParam(array $arguments, $name, $defaultValue) {
+    if (isset($arguments[$name])) {
+      return $arguments[$name];
+    } else {
+      return $defaultValue;
     }
-    if ($val == null) {
-      $val = $def;
-    }
-    return $val;
   }
 
   public function getBypassSpecCache() {
@@ -67,13 +64,6 @@
     return $this->requestTokenSecret;
   }
 
-  public static function parseBypassSpecCacheParam() {
-    if (isset($_REQUEST[self::$BYPASS_SPEC_CACHE_PARAM])) {
-      return "1" == $_REQUEST[self::$BYPASS_SPEC_CACHE_PARAM];
-    }
-    return false;
-  }
-
   public function getServiceName() {
     return $this->serviceName;
   }