Example #1
0
 public function __construct($services)
 {
     foreach ($services as $service) {
         $oauthService = new OAuthService($service);
         $this->oAuthServices[$oauthService->getName()] = $oauthService;
     }
 }
Example #2
0
 /**
  * Dispatches to methods that handle various requirements of a first
  * instantiation.
  */
 protected static function _initStaticProperties()
 {
     self::_validateSettings();
     // The database functionality is optional
     if (OAUTH_DB_DSN) {
         self::$_dbConn = \PFXUtils::getDBConn(OAUTH_DB_DSN, OAUTH_DB_USER, OAUTH_DB_PASSWORD);
         self::_initDBStatements();
         self::_destroyExpiredTokens();
     }
     self::$_staticPropsReady = true;
 }
Example #3
0
 /**
  * Parses the gadget's OAuth entries, the OAuth entry would look something like:
  * <OAuth>
  *   <Service name="google">
  *     <Access url="https://www.google.com/accounts/OAuthGetAccessToken" method="GET" />
  *     <Request url="https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/m8/feeds/" method="GET" />
  *     <Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback" />
  *   </Service>
  * </OAuth>
  *
  * And the resulting $gadgetSpec->oauth structure:
  *
  * Array (
  *     [access] => Array (
  *             [url] => https://www.google.com/accounts/OAuthGetAccessToken
  *             [method] => GET
  *         )
  *     [request] => Array (
  *             [url] => https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/m8/feeds/
  *             [method] => GET
  *         )
  *     [authorization] => Array (
  *             [url] => https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback
  *             [method] => GET
  *         )
  * )
  *
  * @param DOMElement $modulePrefs
  * @param GadgetSpec $gadget
  */
 private function parseOAuth(DOMElement &$modulePrefs, GadgetSpec &$gadget)
 {
     if (($oauthNodes = $modulePrefs->getElementsByTagName('OAuth')) != null) {
         if ($oauthNodes->length > 1) {
             throw new GadgetSpecException("A gadget can only have one OAuth element (though multiple service entries are allowed in that one OAuth element)");
         }
         $oauth = array();
         if ($oauthNodes->length > 0) {
             $oauthNode = $oauthNodes->item(0);
             if (($serviceNodes = $oauthNode->getElementsByTagName('Service')) != null) {
                 foreach ($serviceNodes as $service) {
                     $oauthService = new OAuthService($service);
                     $oauth[$oauthService->getName()] = $oauthService;
                 }
             }
             $gadget->oauth = $oauth;
         }
     }
 }
 /**
  * Get CDN OAuth access and retrieve API Credentials
  *
  * @return void
  */
 function action_cdn_oauth_access()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     include W3TC_LIB_OAUTH_DIR . '/OAuthService.php';
     $type = W3_Request::get_string('type');
     $oauthClient = OAuthService::get_oauth_client($type);
     $oauthClient->print_javascript();
 }
 /**
  * @covers Crockett95\ProjectPlace\OAuthService::__construct
  * @covers Crockett95\ProjectPlace\OAuthService::getRequestTokenEndpoint
  * @covers Crockett95\ProjectPlace\OAuthService::parseAccessTokenResponse
  */
 public function testParseAccessTokenResponseValid()
 {
     $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
     $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('oauth_token=foo&oauth_token_secret=bar'));
     $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface');
     $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface');
     $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token));
     $service = new OAuthService($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), $client, $storage, $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'));
     $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar', $token));
 }