Example #1
0
 /**
  * Verify the Facebook credentials.
  *
  * @throws	Kohana_Exception
  * @param	string	the service name
  * @return	boolean
  */
 public function verify($service = MMI_API::SERVICE_FACEBOOK)
 {
     $access_token = NULL;
     if (!array_key_exists('fragment', $_GET)) {
         $this->_convert_fragment_to_parameter();
     } else {
         $fragment = urldecode(Security::xss_clean($_GET['fragment']));
         parse_str($fragment, $parms);
         $access_token = Arr::get($parms, 'access_token');
         unset($parms);
     }
     // Ensure the access token is set
     if (empty($access_token)) {
         MMI_Log::log_error(__METHOD__, __LINE__, 'Access token parameter missing');
         throw new Kohana_Exception('Access token parameter missing in :method.', array(':method' => __METHOD__));
     }
     // Load existing data from the database
     $auth_config = $this->_auth_config;
     $username = Arr::get($auth_config, 'username');
     $model;
     if (!empty($username)) {
         $model = Model_MMI_API_Tokens::select_by_service_and_username($service, $username, FALSE);
     } else {
         $consumer_key = Arr::get($auth_config, 'api_key');
         $model = Model_MMI_API_Tokens::select_by_service_and_consumer_key($service, $consumer_key, FALSE);
     }
     $success = FALSE;
     $previously_verified = FALSE;
     if ($model->loaded()) {
         // Check if the credentials were previously verified
         $previously_verified = $model->verified;
         $success = $previously_verified;
     }
     if (!$previously_verified) {
         // Create an access token
         $token = new OAuthToken($access_token, $service . '-' . time());
         // Update the token credentials in the database
         $svc = MMI_API::factory($service);
         if (isset($token) and $svc->is_valid_token($token)) {
             $encrypt = Encrypt::instance();
             $model->service = $service;
             $model->consumer_key = 'consumer-' . $service;
             $model->consumer_secret = $encrypt->encode($service . '-' . time());
             $model->token_key = $token->key;
             $model->token_secret = $encrypt->encode($token->secret);
             unset($encrypt);
             $model->verified = 1;
             $model->verification_code = $service . '-' . time();
             $model->username = $username;
             if (array_key_exists('expires_in', $_GET)) {
                 $model->attributes = array('expires_in' => urldecode(Security::xss_clean($_GET['expires_in'])));
             }
             $success = MMI_Jelly::save($model, $errors);
             if (!$success and $this->_debug) {
                 MMI_Debug::dead($errors);
             }
         }
     }
     return $success;
 }
Example #2
0
 /**
  * Verify the Flickr credentials.
  *
  * @throws	Kohana_Exception
  * @return	boolean
  */
 public function verify()
 {
     // Set the service
     $service = $this->_service;
     if (empty($service)) {
         MMI_Log::log_error(__METHOD__, __LINE__, 'Service not set');
         throw new Kohana_Exception('Service not set in :method.', array(':method' => __METHOD__));
     }
     // Ensure the frob is set
     $frob = NULL;
     if (array_key_exists('frob', $_GET)) {
         $frob = urldecode(Security::xss_clean($_GET['frob']));
     }
     if (empty($frob)) {
         MMI_Log::log_error(__METHOD__, __LINE__, 'Frob parameter missing');
         throw new Kohana_Exception('Frob parameter missing in :method.', array(':method' => __METHOD__));
     }
     // Load existing data from the database
     $auth_config = $this->_auth_config;
     $username = Arr::get($auth_config, 'username');
     $model;
     if (!empty($username)) {
         $model = Model_MMI_API_Tokens::select_by_service_and_username($service, $username, FALSE);
     } else {
         $model = Jelly::factory('MMI_API_Tokens');
     }
     $success = FALSE;
     if ($model->loaded()) {
         // Check if the credentials were previously verified
         $previously_verified = $model->verified;
         if ($previously_verified) {
             $success = TRUE;
         } else {
             // Create a dummy verification code
             $verification_code = $service . '-' . time();
         }
         // Do database update
         if (!$previously_verified) {
             // Get an access token
             $svc = MMI_API::factory($service);
             $token = $svc->get_access_token($verification_code, array('token_key' => $frob, 'token_secret' => $service . '-' . time()));
             // Update the token credentials in the database
             if (isset($token) and $svc->is_valid_token($token)) {
                 $model->token_key = $token->key;
                 $model->token_secret = Encrypt::instance()->encode($token->secret);
                 $model->verified = 1;
                 $model->verification_code = $verification_code;
                 if (!empty($token->attributes)) {
                     $model->attributes = $token->attributes;
                 }
                 $success = MMI_Jelly::save($model, $errors);
                 if (!$success and $this->_debug) {
                     MMI_Debug::dead($errors);
                 }
             }
         }
     }
     return $success;
 }
Example #3
0
 /**
  * Get the OAuth credentials model from the database.
  *
  * @return	Jelly_Model
  */
 protected function _get_db_model()
 {
     $model;
     $service = $this->_service;
     $username = $this->_username;
     if (!empty($username)) {
         $model = Model_MMI_API_Tokens::select_by_service_and_username($service, $username, FALSE);
     } else {
         $model = Model_MMI_API_Tokens::select_by_service_and_consumer_key($service, $this->_consumer->key, FALSE);
     }
     return $model;
 }
Example #4
0
 /**
  * Get the auth credentials model from the database.
  *
  * @return	Jelly_Model
  */
 protected function _get_db_model()
 {
     $model;
     $username = $this->_username;
     if (!empty($username)) {
         $model = Model_MMI_API_Tokens::select_by_service_and_username($this->_service, $username, FALSE);
     } else {
         $model = Jelly::factory('MMI_API_Tokens');
     }
     return $model;
 }