/** * google+ oauth 2 redirect_uri call * * If you get an error like: Unable to Connect to ssl://www.google.com:443 * ensure open_ssl extension is enabled in your php.ini, then restart apache */ public function googlepluscallbackAction() { $rawCode = $this->_request->getParam('code', null); $stateParameter = $this->_request->getParam('state', null); $errorReason = $this->_request->getParam('error_reason', null); $oauthSessionNamespace = new Zend_Session_Namespace('oauthSessionNamespace'); //Zend_Debug::dump($stateParameter, '$stateParameter'); //Zend_Debug::dump($oauthSessionNamespace->state, '$oauthSessionNamespace->state'); if (is_null($stateParameter)) { // user refused to grant permission(s) Zend_Debug::dump('dialog no valid state found'); exit; } else { if ($stateParameter !== $oauthSessionNamespace->state) { Zend_Debug::dump('dialog state values don\'t match'); exit; } } if (!is_null($errorReason)) { // user refused to grant permission(s) Zend_Debug::dump('user refused to grant permission(s): ' . $errorReason); exit; } $filterChain = $this->getFilterChain(); $verificationCode = $filterChain->filter($rawCode); $googlePlusOAuth2Configuration = new Zend_Config_Ini(APPLICATION_PATH . '/configs/google_plus_api.ini'); $chriswebOauth2 = new Chrisweb_Oauth2($googlePlusOAuth2Configuration); $oauthResponse = null; try { /** * if you try to exchange an expired or invalid token, google will * reply "invalid_grant" */ $oauthResponse = $chriswebOauth2->requestAccessToken($verificationCode); } catch (Exception $e) { Zend_Debug::dump($e->getMessage(), 'error'); } if (is_array($oauthResponse)) { Zend_Debug::dump($oauthResponse, '$oauthResponse: '); // save OAuth Response $oauthSessionNamespace->oauthResponse = $oauthResponse; } }
/** * jamendo oauth 2 redirect_uri call * * If you get an error like: Unable to Connect to ssl://www.jamendo.com:443 * ensure open_ssl extension is enabled in your php.ini, then restart apache */ public function jamendocallbackAction() { $rawCode = $this->_request->getParam('code', null); $stateParameter = $this->_request->getParam('state', null); $errorReason = $this->_request->getParam('error_reason', null); $oauthSessionNamespace = new Zend_Session_Namespace('oauthSessionNamespace'); if (is_null($stateParameter)) { // user refused to grant permission(s) Zend_Debug::dump('no valid state found'); exit; } else { if ($stateParameter !== $oauthSessionNamespace->state) { Zend_Debug::dump('state values don\'t match'); exit; } } if (!is_null($errorReason)) { // user refused to grant permission(s) Zend_Debug::dump('user refused to grant permission(s): ' . $errorReason); exit; } $filterChain = $this->getFilterChain(); $verificationCode = $filterChain->filter($rawCode); $jamendoOAuth2Configuration = new Zend_Config_Ini(APPLICATION_PATH . '/configs/jamendo_api.ini'); $chriswebOauth2 = new Chrisweb_Oauth2($jamendoOAuth2Configuration); $oauthResponse = null; try { $oauthResponse = $chriswebOauth2->requestAccessToken($verificationCode); } catch (Exception $e) { Zend_Debug::dump($e->getMessage(), 'error: '); } if (is_array($oauthResponse)) { Zend_Debug::dump($oauthResponse, '$oauthResponse: '); // save OAuth Response $oauthSessionNamespace->oauthResponse = $oauthResponse; } }
/** * Simple mechanism to delete the entire singleton HTTP Client instance * which forces an new instantiation for subsequent requests. * * @return void */ public static function clearHttpClient() { self::$httpClient = null; }