public static function createFromConfigs(Zend_Config $config, $userId) { $databaseFactory = new EngineBlock_Database_ConnectionFactory(); $databaseAdapter = $databaseFactory->create(EngineBlock_Database_ConnectionFactory::MODE_READ); $accessTokenHelper = new EngineBlock_Group_Provider_OpenSocial_Oauth_Helper_AccessToken($config->id, $databaseAdapter, $userId); $authConfig = $config->auth->toArray(); if (isset($authConfig['rsaPrivateKey'])) { if (empty($authConfig['rsaPrivateKey'])) { unset($authConfig['rsaPrivateKey']); } else { $authConfig['rsaPrivateKey'] = new Zend_Crypt_Rsa_Key_Private($authConfig['rsaPrivateKey']); } } if (isset($authConfig['rsaPublicKey'])) { if (empty($authConfig['rsaPublicKey'])) { unset($authConfig['rsaPublicKey']); } else { $authConfig['rsaPublicKey'] = new Zend_Crypt_Rsa_Key_Public($authConfig['rsaPublicKey']); } } $httpClient = new Zend_Oauth_Client($authConfig, $config->url, $config); $accessToken = $accessTokenHelper->loadAccessToken(); if ($accessToken) { $httpClient->setToken($accessToken); } $openSocialRestClient = new OpenSocial_Rest_Client($httpClient); $provider = new self($config->id, $config->name, $openSocialRestClient); $provider->setUserId($userId); $provider->setAccessTokenHelper($accessTokenHelper); $provider->addPrecondition('EngineBlock_Group_Provider_Precondition_OpenSocial_Oauth_AccessTokenExists'); $provider->configurePreconditions($config); $provider->configureGroupFilters($config); $provider->configureGroupMemberFilters($config); $decoratedProvider = $provider->configureDecoratorChain($config); return $decoratedProvider; }
/** * @group ZF-10851 */ public function testOauthClientPreparationWithRealmConfigurationOption() { require_once "Zend/Oauth/Token/Access.php"; $options = array( 'requestMethod' => 'GET', 'siteUrl' => 'http://www.example.com', 'realm' => 'someRealm' ); $token = new Zend_Oauth_Token_Access(); require_once 'Zend/Oauth/Client.php'; $client = new Zend_Oauth_Client($options); $this->assertEquals(NULL,$client->getHeader('Authorization')); $client->setToken($token); $client->setUri('http://oauth.example.com'); $client->prepareOauth(); $this->assertNotContains('realm=""',$client->getHeader('Authorization')); $this->assertContains('realm="someRealm"',$client->getHeader('Authorization')); }
/** * Get OAuth client * * @param array $oauthOptions * @param null|string $uri * @param null|array|Zend_Config $config * @param bool $excludeCustomParamsFromHeader * @return Zend_Oauth_Client */ public function getHttpClient(array $oauthOptions, $uri = null, $config = null, $excludeCustomParamsFromHeader = true) { $client = new Zend_Oauth_Client($oauthOptions, $uri, $config, $excludeCustomParamsFromHeader); $client->setToken($this); return $client; }
/** * @group ZF-11663 */ public function testOauthClientAcceptsGetParametersThroughSetter() { require_once "Zend/Oauth/Token/Access.php"; $token = new Zend_Oauth_Token_Access(); $options = array('requestMethod' => 'GET', 'requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING, 'realm' => 'someRealm'); require_once 'Zend/Oauth/Client.php'; $client = new Zend_Oauth_Client($options); $client->setToken($token); $client->setUri('http://www.example.com/?test=FooBar'); $queryString = $client->getUri()->getQuery(); // Check that query string was set properly $this->assertSame('test=FooBar', $queryString); // Change the GET parameters $client->setParameterGet('test', 'FooBaz'); $client->setParameterGet('second', 'TestTest'); // Prepare the OAuth request $client->prepareOauth(); $queryString = $client->getUri()->getQuery(); // Ensure that parameter 'test' is unchanged, as URI parameters // should take precedence over ones set with setParameterGet $this->assertContains('test=FooBar', $queryString); // Ensure that new parameter was added $this->assertContains('second=TestTest', $queryString); }