/** * @param array $contents * * @throws \DreamFactory\Oasys\Exceptions\OasysException */ public function __construct($contents = array()) { if (!isset($_SESSION) || PHP_SESSION_DISABLED == session_status()) { throw new OasysException('No session active. Session storage not available.'); } $_data = array(); if (null !== ($_parcel = Option::get($_SESSION, static::KEY_PREFIX . '.data'))) { $_data = Storage::defrost($_parcel); } if (is_array($_data)) { $_data = array_merge($_data, $contents); } parent::__construct($_data); }
/** * Handle inbound redirect from various services * * @throws DreamFactory\Platform\Exceptions\RestException */ public function actionAuthorize() { Log::debug('Inbound $REQUEST: ' . print_r($_REQUEST, true)); $_state = Storage::defrost(Option::request('state')); $_origin = Option::get($_state, 'origin'); $_apiKey = Option::get($_state, 'api_key'); Log::debug('Inbound state: ' . print_r($_state, true)); if (empty($_origin) || empty($_apiKey)) { Log::error('Invalid request state.'); throw new BadRequestException(); } if ($_apiKey != ($_testKey = sha1($_origin))) { Log::error('API Key mismatch: ' . $_apiKey . ' != ' . $_testKey); throw new ForbiddenException(); } $_code = FilterInput::request('code', null, FILTER_SANITIZE_STRING); if (!empty($_code)) { Log::debug('Inbound code received: ' . $_code . ' from ' . $_state['origin']); } else { if (null === Option::get($_REQUEST, 'access_token')) { Log::error('Inbound request code missing.'); throw new RestException(HttpResponse::BadRequest); } else { Log::debug('Token received. Relaying to origin.'); } } $_redirectUri = Option::get($_state, 'redirect_uri', $_state['origin']); $_redirectUrl = $_redirectUri . (false === strpos($_redirectUri, '?') ? '?' : '&') . \http_build_query($_REQUEST); Log::debug('Proxying request to: ' . $_redirectUrl); header('Location: ' . $_redirectUrl); exit; }
/** * Given an inbound state string, convert to original defrosted state * * @param string $state If not supplied, $_REQUEST['state'] is used. * * @return array */ protected static function _decodeState($state = null) { if (null === ($_state = $state ?: Option::request('state'))) { return array(); } return Storage::defrost($_state); }
/** * Loads any stored data for this ID * * @return bool */ protected function _load() { $_file = $this->_storagePath . DIRECTORY_SEPARATOR . $this->_fileName; if (is_file($_file) && file_exists($_file) && is_readable($_file)) { if (false !== ($_data = Utility\Storage::defrost(file_get_contents($_file)))) { // If it wasn't frozen, a JSON string may be returned if (is_string($_data) && false !== json_decode($_data)) { $_data = json_decode($_data, true); } $this->merge($_data); return true; } } return false; }
/** * Deserialize */ public static function __wakeup() { // Load options from session... if (PHP_SESSION_DISABLED != session_status() && null !== ($_frozen = Option::get($_SESSION, CoreSettings::SESSION_KEY))) { // Merge them into the fold $_data = Storage::defrost($_frozen); // If this object wasn't stored by me, don't use it. if ($_data == $_frozen) { Log::debug(' - Retrieved data is not compressed or bogus. Removing. '); unset($_SESSION[CoreSettings::SESSION_KEY]); return; } static::$_options = Options::merge($_data, static::$_options); } static::$_awake = true; }