/** * @return bool * @throws \DreamFactory\Oasys\Exceptions\OasysException */ public function sync() { if (!isset($_SESSION) || PHP_SESSION_DISABLED == session_status()) { throw new OasysException('No session active. Session storage not available.'); } $_settings = $this->contents(); if (!empty($_settings)) { $_SESSION[static::KEY_PREFIX . '.data'] = Storage::freeze($_settings); } return true; }
/** * 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; }
/** * Creates a compact string representing $data * * @param array $data * * @return string */ protected static function _encodeState($data = array()) { return Storage::freeze($data); }
/** * Construct a link to authorize the application * * @param array $payload * * @return string */ public function getAuthorizationUrl($payload = array()) { $_map = $this->_config->getEndpoint(EndpointTypes::AUTHORIZE); $_scope = $this->getConfig('scope'); $_referrer = Option::get($this->_requestPayload, 'referrer', Option::server('HTTP_REFERER', Curl::currentUrl()), true); $_redirectUri = $this->getConfig('redirect_uri', $_referrer); $_origin = $this->getConfig('origin_uri', $_redirectUri); $_proxyUrl = $this->getConfig('redirect_proxy_url'); $_state = array('request' => array('method' => Option::server('REQUEST_METHOD'), 'referrer' => $_referrer, 'query_string' => Option::server('QUERY_STRING'), 'remote_addr' => Option::server('REMOTE_ADDR'), 'time' => microtime(true), 'uri' => Option::server('REQUEST_URI'), 'payload' => $this->_requestPayload), 'origin' => $_origin, 'api_key' => sha1($_origin), 'redirect_uri' => $_redirectUri); Log::debug('Request state built: ' . print_r($_state, true)); $_payload = array_merge(array('client_id' => $this->getConfig('client_id'), 'redirect_uri' => $_redirectUri, 'response_type' => 'code', 'scope' => is_array($_scope) ? implode(' ', $_scope) : $_scope, 'state' => Storage::freeze($_state)), Option::clean(Option::get($_map, 'parameters', array()))); if (!empty($_proxyUrl)) { Log::info('Proxying request through: ' . $_proxyUrl); $_payload['redirect_uri'] = $_proxyUrl; } $_qs = http_build_query($_payload); $this->setConfig('authorize_url', $_authorizeUrl = $_map['endpoint'] . Curl::urlSeparator($_map['endpoint']) . $_qs); Log::debug('Authorization URL created: ' . $_authorizeUrl); return $_authorizeUrl; }
/** * 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; }