Пример #1
0
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     if ($request->getParam('error')) {
         $this->_addError($request->getParam('error_description'));
         return false;
     }
     try {
         $cookie = new Garp_Store_Cookie('Garp_Auth');
         // User returns from LinkedIn and has authorized the app
         if ($request->getParam('code')) {
             $accessToken = $this->_getLinkedInInstance()->getAccessToken($request->getParam('code'));
             if ($cookie->extendedUserColumns) {
                 $this->setExtendedUserColumns(unserialize($cookie->extendedUserColumns));
                 $cookie->destroy('extendedUserColumns');
             }
             return $this->_getUserData($accessToken);
         }
         // User has not interacted yet, and needs to authorize the app
         if (!empty($this->_extendedUserColumns)) {
             $cookie->extendedUserColumns = serialize($this->_extendedUserColumns);
         }
         $cookie->writeCookie();
         $authorizeUrl = $this->_getLinkedInInstance()->getLoginUrl(array(LinkedIn::SCOPE_BASIC_PROFILE, LinkedIn::SCOPE_EMAIL_ADDRESS));
         Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->gotoUrl($authorizeUrl);
         return false;
     } catch (Exception $e) {
         if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) {
             $this->_addError(__('this email address already exists'));
             return false;
         }
         $this->_addError(APPLICATION_ENV === 'development' ? $e->getMessage() : __('login error'));
         return false;
     }
 }
Пример #2
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $facebook = $this->_getFacebookClient();
     $authVars = $this->_getAuthVars();
     $cookie = new Garp_Store_Cookie('Garp_Auth');
     /**
      * Send the user to Facebook to login and give us access.
      * This happens when the form on the login page gets posted.
      * Then this request will be made one more time; when the user comes back from Facebook.
      * At that point he might has given us access, which is
      * checked in the try {...} catch(){...} block below.
      * Just note that any POST request here results in the user being redirected to Facebook.
      */
     if ($request->isPost()) {
         if (!empty($this->_extendedUserColumns)) {
             $cookie->extendedUserColumns = serialize($this->_extendedUserColumns);
         }
         $cookie->writeCookie();
         $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
         $scope = isset($authVars->scope) ? $authVars->scope : null;
         $redirector->gotoUrl($facebook->getLoginUrl(array('scope' => $scope)));
         exit;
     }
     // Session based API call.
     try {
         if ($cookie->extendedUserColumns) {
             $this->setExtendedUserColumns(unserialize($cookie->extendedUserColumns));
             $cookie->destroy('extendedUserColumns');
         }
         $userData = $facebook->login(!!$authVars->grabUserImage);
         $userData = $this->_getUserData($userData);
         // Automatically fetch friends if so configured.
         if (!empty($authVars->friends->collect) && $authVars->friends->collect) {
             $bindingModel = 'Model_UserUser';
             // A Sensible Default™
             if (empty($authVars->friends->bindingModel)) {
                 $bindingModel = $authVars->friends->bindingModel;
             }
             $facebook->mapFriends(array('bindingModel' => $bindingModel, 'user_id' => $userData['id']));
         }
         return $userData;
     } catch (FacebookApiException $e) {
         $this->_addError($e->getMessage());
         return false;
     } catch (Exception $e) {
         if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) {
             $this->_addError(__('this email address already exists'));
             return false;
         }
         throw $e;
         $this->_addError(__('login error'));
         return false;
     }
 }
Пример #3
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $callbackUrl = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $request->getBaseUrl() . '/g/auth/login/process/twitter';
     $authVars = $this->_getAuthVars();
     if (!$authVars->consumerKey || !$authVars->consumerSecret) {
         throw new Garp_Auth_Exception('Required key "consumerKey" or "consumerSecret" not set in application.ini.');
     }
     $config = array('siteUrl' => 'https://api.twitter.com/oauth', 'consumerKey' => $authVars->consumerKey, 'consumerSecret' => $authVars->consumerSecret, 'callbackUrl' => $callbackUrl);
     try {
         $consumer = new Zend_Oauth_Consumer($config);
         if ($request->isPost()) {
             $token = $consumer->getRequestToken();
             $cookie = new Garp_Store_Cookie('Garp_Auth');
             $cookie->token = serialize($token);
             if (!empty($this->_extendedUserColumns)) {
                 $cookie->extendedUserColumns = serialize($this->_extendedUserColumns);
             }
             $cookie->writeCookie();
             $consumer->redirect();
             return true;
         }
         $cookie = new Garp_Store_Cookie('Garp_Auth');
         if ($request->getParam('oauth_token') && isset($cookie->token)) {
             $accesstoken = $consumer->getAccessToken($_GET, unserialize($cookie->token));
             // Discard request token
             if ($cookie->extendedUserColumns) {
                 $this->setExtendedUserColumns(unserialize($cookie->extendedUserColumns));
                 $cookie->destroy('extendedUserColumns');
             }
             $cookie->destroy('oauth_token');
             return $this->_getUserData($this->_getTwitterService($accesstoken, $authVars->consumerKey, $authVars->consumerSecret), $accesstoken->getParam('user_id'));
         }
         $this->_addError('App was not authorized. Please try again.');
         return false;
     } catch (Exception $e) {
         if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) {
             $this->_addError(__('this email address already exists'));
             return false;
         }
         // Provide generic error message
         $this->_addError(APPLICATION_ENV === 'development' ? $e->getMessage() : __('login error'));
     }
     return false;
 }
Пример #4
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $callbackUrl = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $request->getBaseUrl() . '/g/auth/login/process/vimeo';
     $authVars = $this->_getAuthVars();
     if (!$authVars->consumerKey || !$authVars->consumerSecret) {
         throw new Garp_Auth_Exception('Required key "consumerKey" or "consumerSecret" not set in application.ini.');
     }
     $config = array('siteUrl' => 'http://vimeo.com/oauth', 'consumerKey' => $authVars->consumerKey, 'consumerSecret' => $authVars->consumerSecret, 'callbackUrl' => $callbackUrl);
     try {
         $consumer = new Zend_Oauth_Consumer($config);
         if ($request->isPost()) {
             $token = $consumer->getRequestToken();
             $cookie = new Garp_Store_Cookie('Garp_Auth');
             if (!empty($this->_extendedUserColumns)) {
                 $cookie->extendedUserColumns = serialize($this->_extendedUserColumns);
             }
             $cookie->token = serialize($token);
             $cookie->writeCookie();
             $consumer->redirect();
             exit;
         } elseif ($request->getParam('oauth_token')) {
             $cookie = new Garp_Store_Cookie('Garp_Auth');
             if (isset($cookie->token)) {
                 $accesstoken = $consumer->getAccessToken($_GET, unserialize($cookie->token));
                 if ($cookie->extendedUserColumns) {
                     $this->setExtendedUserColumns(unserialize($cookie->extendedUserColumns));
                     $cookie->destroy('extendedUserColumns');
                 }
                 // Discard request token
                 $cookie->destroy('token');
                 return $this->_getUserData($accesstoken);
             } else {
                 $this->_addError('App was not authorized. Please try again.');
             }
         } elseif ($request->getParam('denied')) {
             $this->_addError('App was not authorized. Please try again.');
         }
     } catch (Exception $e) {
         $this->_addError($e->getMessage());
     }
     return false;
 }
Пример #5
0
 /**
  * Remove role cookie
  *
  * @return void
  */
 protected function _removeRoleCookie()
 {
     // Use the cookie store to destroy the cookie.
     $store = new Garp_Store_Cookie('Garp_Auth');
     $store->destroy();
 }
Пример #6
0
 protected function clearAllPersistentData()
 {
     $this->_store->destroy();
 }