Beispiel #1
0
 /**
  * Revoke a user's app auth on Facebook
  *
  * @param string $providerUserId
  *
  * @throws \DreamFactory\Platform\Exceptions\BadRequestException
  */
 protected function _revokeAuthorization($providerUserId = null)
 {
     $_id = $providerUserId ?: null;
     if (empty($providerUserId) && null === ($_id = $this->getConfig('provider_user_id'))) {
         $_profile = $this->getUserData();
         if (!empty($_profile) && null !== ($_id = $_profile->getUserId())) {
             throw new BadRequestException('Revocation not possible without provider user ID.');
         }
     }
     $_result = $this->fetch('/' . $_id . '/permissions', array(), HttpMethod::Delete);
     if (true !== ($_success = Option::get($_result, 'result', false))) {
         if (HttpResponse::BadRequest !== Option::get($_result, 'code')) {
             Log::error('Facebook revocation for user ID "' . $_id . '" FAILED.');
             return;
         } else {
             Log::debug('Facebook revocation for user ID "' . $_id . '" already completed.');
         }
     } else {
         Log::debug('Facebook revocation for user ID "' . $_id . '" successful.');
     }
     parent::_revokeAuthorization();
 }
Beispiel #2
0
 protected function _checkSystemState()
 {
     $_error = false;
     $_state = SystemManager::getSystemState();
     if (!$this->_activated && $_state != PlatformStates::INIT_REQUIRED) {
         $_state = PlatformStates::ADMIN_REQUIRED;
     }
     if (!empty($this->_remoteError)) {
         $_error = 'error=' . urlencode($this->_remoteError);
     }
     if (PlatformStates::READY == $_state) {
         $_defaultApp = Pii::getParam('dsp.default_app', static::DEFAULT_STARTUP_APP);
         //	Try local launchpad
         if (is_file(\Kisma::get('app.app_path') . $_defaultApp)) {
             $_defaultApp = rtrim($_defaultApp . Curl::urlSeparator($_defaultApp) . $_error, '?');
             $this->redirect($_defaultApp);
         }
         //            Log::notice(
         //                'No default application defined/found. Running launchpad...' .
         //                PHP_EOL .
         //                '==============================' .
         //                PHP_EOL .
         //                'Config dump:' .
         //                PHP_EOL .
         //                print_r( \Kisma::get( null ), true ) .
         //                '==============================' .
         //                PHP_EOL .
         //                '==============================' .
         //                PHP_EOL .
         //                'Params dump:' .
         //                PHP_EOL .
         //                print_r( Pii::params(), true ) .
         //                '==============================' .
         //                PHP_EOL
         //            );
         //	If we have no app, run the launchpad
         $this->redirect(static::DEFAULT_STARTUP_APP);
     } else {
         if (!$this->_handleAction($_state)) {
             Log::error('Invalid state "' . $_state . '" or no handler configured.');
         }
     }
 }
Beispiel #3
0
 /**
  * @param array|null $parameters
  *
  * @return bool
  */
 public function execute($parameters = null)
 {
     if (empty($parameters)) {
         $_result = $this->_statement->execute();
     } else {
         $_result = $this->_statement->execute($parameters);
     }
     if (false === $_result) {
         $this->_errorInfo = $this->_statement->errorInfo();
         Log::error('SQL error: [' . $this->_errorInfo[0] . '-' . $this->_errorInfo[1] . '] ' . $this->_errorInfo[2]);
     }
     return $this->_executeResult = $_result;
 }
Beispiel #4
0
 /**
  * Checks the progress of any in-flight OAuth requests
  *
  *
  * @throws \Exception|\OAuthException
  * @throws \DreamFactory\Oasys\Exceptions\RedirectRequiredException
  * @return string
  */
 public function checkAuthenticationProgress()
 {
     if ($this->_config->getAccessToken()) {
         $this->_setToken();
         return true;
     }
     $_state = $this->_config->getState();
     $_accessToken = null;
     $_requestToken = Option::request('oauth_token');
     $_tokenSecret = Option::request('oauth_secret', $this->_config->getAccessTokenSecret());
     $_verifier = Option::request('oauth_verifier');
     try {
         //	No auth yet
         if (null === $_requestToken) {
             $_url = $this->_config->getEndpointUrl(EndpointTypes::REQUEST_TOKEN);
             $_token = $this->getRequestToken($_url);
             $this->setAccessTokenSecret($_tokenSecret = Option::get($_token, 'oauth_token_secret'));
             $this->setState(1);
             //	Construct the redirect for authorization
             $_redirectUrl = $this->getEndpointUrl(EndpointTypes::AUTHORIZE) . '?oauth_token=' . Option::get($_token, 'oauth_token');
             if (!empty($this->_redirectProxyUrl)) {
                 $_redirectUrl = $this->_redirectProxyUrl . '?redirect=' . urlencode($_redirectUrl);
             }
             $this->_config->setAuthorizeUrl($_redirectUrl);
             if (Flows::SERVER_SIDE == $this->_config->getFlowType()) {
                 throw new RedirectRequiredException($_redirectUrl);
             }
             header('Location: ' . $_redirectUrl);
             exit;
         }
         //	Step 2!
         if (!empty($_requestToken) && !empty($_verifier)) {
             $this->_client->setToken($_requestToken, $_tokenSecret);
             $_accessToken = $this->_client->getAccessToken($this->_config->getEndpointUrl(EndpointTypes::ACCESS_TOKEN));
             $this->_config->setState($_state = 2);
             $this->_config->setToken($_accessToken);
             $this->_config->setAccessToken($_accessToken['oauth_token']);
             $this->_config->setAccessTokenSecret($_accessToken['oauth_token_secret']);
         }
         //	Set the token, now ready for action
         if (2 == $_state) {
             $this->_setToken();
         }
     } catch (\OAuthException $_ex) {
         Log::error('OAuth exception: ' . $_ex->getMessage());
         throw $_ex;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Validates an inbound relay request
  *
  * @param string $state If not supplied, $_REQUEST['state'] is used.
  *
  * @throws \Kisma\Core\Exceptions\HttpException
  * @return array
  */
 public static function validateAuthState($state = null)
 {
     $_state = static::_decodeState($state);
     $_origin = Option::get($_state, 'origin');
     $_apiKey = Option::get($_state, 'api_key');
     if (empty($_origin) || empty($_apiKey)) {
         throw new HttpException(HttpResponse::BadRequest, 'Invalid auth state');
     }
     if ($_apiKey != ($_testKey = sha1($_origin))) {
         Log::error('API Key mismatch: ' . $_apiKey . ' != ' . $_testKey);
         throw new HttpException(HttpResponse::Forbidden, 'Invalid API key');
     }
     return $_state;
 }
Beispiel #6
0
$_fabricHosted = false;
if (!defined('DSP_VERSION') && file_exists(__DIR__ . '/constants.config.php')) {
    require __DIR__ . '/constants.config.php';
}
/**
 * Load any environment variables first thing as they may be used by the database config
 */
/** @noinspection PhpIncludeInspection */
if (false !== ($_envConfig = Pii::includeIfExists(__DIR__ . ENV_CONFIG_PATH, true))) {
    if (!empty($_envConfig) && is_array($_envConfig)) {
        foreach ($_envConfig as $_key => $_value) {
            if (!is_string($_value)) {
                $_value = json_encode($_value);
            }
            if (false === putenv($_key . '=' . $_value)) {
                Log::error('Error setting environment variable: ' . $_key . ' = ' . $_value);
            }
        }
    }
}
/**
 * Load up the database configuration, free edition, private hosted, or others.
 * Look for non-default database config to override.
 */
if (false === ($_dbConfig = Pii::includeIfExists(__DIR__ . DATABASE_CONFIG_PATH, true))) {
    if (Fabric::fabricHosted()) {
        $_fabricHosted = true;
        list($_dbConfig, $_metadata) = Fabric::initialize();
    } else {
        /**
         * Database names vary by type of DSP:
Beispiel #7
0
 /**
  * Choose your destructor!
  */
 public function __destruct()
 {
     if (is_resource($this->_handle)) {
         if (false === @fclose($this->_handle)) {
             Log::error('Error whilst closing file: ' . $this->_fileName);
         }
     }
 }
Beispiel #8
0
 * console.php
 * This is the main configuration file for the DreamFactory Services Platform server console.
 */
if (!defined('DSP_VERSION') && file_exists(__DIR__ . '/constants.config.php')) {
    require __DIR__ . '/constants.config.php';
}
$_configFileList = array('dbConfig' => array(true, 'database'), 'commonConfig' => array(true, 'common'));
/**
 * Load any environment variables first thing as they may be used by the database config
 */
if (file_exists(__DIR__ . '/env.config.php')) {
    /** @noinspection PhpIncludeInspection */
    if (false !== ($_envConfig = @(require __DIR__ . '/env.config.php')) && !empty($_envConfig) && is_array($_envConfig)) {
        foreach ($_envConfig as $_envVar) {
            if (false === putenv($_envVar)) {
                Log::error('Error setting environment variable: ' . $_envVar);
            }
        }
    }
}
/**
 * Load up the common configurations between the web and background apps,
 * setting globals whilst at it.
 */
$_commonConfig = (require __DIR__ . '/common.config.php');
/**
 * Load up the database configuration, free edition, private hosted, or others.
 * Look for non-default database config to override.
 */
$_dbConfig = array();
if (file_exists(__DIR__ . '/database.config.php')) {
Beispiel #9
0
 /**
  * @param array $payload
  *
  * @throws \DreamFactory\Oasys\Exceptions\AuthenticationException
  * @return mixed
  */
 public function requestRefreshToken(array $payload = array())
 {
     if (null === ($_refreshToken = $this->getConfig('refresh_token'))) {
         return false;
     }
     Log::debug('Access token expired or bogus . Requesting refresh: ' . $_refreshToken);
     $_payload = array_merge($payload, array('refresh_token' => $_refreshToken));
     if (false === ($_response = $this->requestAccessToken(GrantTypes::REFRESH_TOKEN, $_payload))) {
         throw new AuthenticationException('Error requesting refresh token: ' . Curl::getErrorAsString());
     }
     $_result = Option::get($_response, 'result');
     //	Did it work?
     if (!empty($_result)) {
         $_payload = (array) $_result;
         $_token = $this->_processReceivedToken($_payload);
         //	It worked! Or not...
         if (null === $_token) {
             Log::error('No access token received: ' . print_r($_payload, true));
             return false;
         }
         Log::debug('Refresh of access token successful for client_id: ' . $this->getConfig('client_id'));
         //	Update user profile with current stuff
         $this->_needProfileUserId = !$this->_singleUser;
         return true;
     }
     Log::error('Error refreshing token . Empty or error response: ' . print_r($_result, true));
     return false;
 }
Beispiel #10
0
 /**
  * Response is always empty from this call. HTTP response code of 204 is success. Anything is an error.
  *
  * @param string $object
  * @param string $id
  * @param array  $fields
  *
  * @throws InternalServerErrorException
  * @return bool|mixed
  */
 public function updateObject($object, $id, $fields = array())
 {
     $_response = $this->fetch('/services/data/' . static::API_VERSION_TAG . '/sobjects/' . $object . '/' . $id, json_encode($fields), static::Patch);
     //	Curl error is false...
     if (false === $_response) {
         return false;
     }
     if (HttpResponse::NoContent == Curl::getLastHttpCode()) {
         return true;
     }
     //	Sometimes they send back xml...
     if (is_string($_response) && false !== stripos($_response, '<?xml')) {
         try {
             if (null === ($_response = Convert::toObject(simplexml_load_string($_response)))) {
                 throw new InternalServerErrorException('Unrecognizable response from server: ' . print_r($_response, true));
             }
             //	Otherwise we have a nice object which we return as json
         } catch (\Exception $_ex) {
             //	error...
             Log::error('Exception parsing response: ' . print_r($_response, true));
         }
     }
     return $_response;
 }
Beispiel #11
0
 /**
  * Saves off any data to the file system
  */
 protected function _save()
 {
     $_file = $this->_storagePath . DIRECTORY_SEPARATOR . $this->_fileName;
     $_data = json_encode($this->contents());
     if ($this->_compressStore) {
         $_data = Utility\Storage::freeze($this->contents());
     }
     if (false === file_put_contents($_file, $_data)) {
         Utility\Log::error('Unable to store Oasys data in "' . $_file . '". System error.');
         return false;
     }
     return true;
 }