/** * Generic call action for all providers * * @param sfWebRequest $request * @return sfView::SUCCESS */ public function executeCall(sfWebRequest $request) { $this->forward404Unless($request->getParameter('provider')); $this->forward404Unless($request->getParameter('method')); $config = sfConfig::get('app_cacophony'); $this->forward404Unless(in_array($request->getParameter('provider'), array_keys($config['providers']))); $params = array(); foreach ($request->getParameterHolder()->getAll() as $k => $p) { if (!in_array($k, array('method', 'action', 'module', 'provider'))) { $params[$k] = $p; } } $result = json_decode(sfCacophonyOAuth::call($request->getParameter('method'), $request->getParameter('provider'), $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $request->getParameter('provider'))), $params)); $this->setVar('result', $result, true); }
/** * Oath 2.0 callback * * @param sfWebRequest $request * @throws Exception */ public function executeCallback2(sfWebRequest $request) { $config = sfConfig::get('app_cacophony'); $provider = $request->getParameter('provider'); if ($request->hasParameter('state')) { // CSFR protection as adviced on the http://developers.facebook.com/docs/authentication/ if ($request->getParameter('state') != $this->getUser()->getAttribute('state', null, sprintf('sfCacophonyPlugin/%s', $provider))) { throw new Exception('CSRF attack detected'); } } if (!$this->getUser()->isAuthenticated() || $config['plugin']['allow_multiple_tokens']) { try { $this->getUser()->setAttribute('accessToken', sfCacophonyOAuth::getAccessToken2($provider, $request->getParameter('code')), sprintf('sfCacophonyPlugin/%s', $provider)); // add me to session $me = sfCacophonyOAuth::getMe($provider, $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $provider))); $this->getUser()->setAttribute('me', $me['normalized'], sprintf('sfCacophonyPlugin/%s', $provider)); } catch (Exception $e) { // $this->getUser()->setFlash('error', sprintf('Failed to retrieve access token: %s', $e->getMessage())); // $this->redirect('@homepage'); throw $e; } } else { $this->redirect('@homepage'); } return sfView::NONE; }