示例#1
0
 /**
  * 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;
 }
示例#2
0
 /**
  * Parses the inbound request + query string into a single KVP array
  *
  * @return array
  */
 protected function _parseRequest()
 {
     $_payload = array();
     if (!empty($_REQUEST)) {
         $_payload = $_REQUEST;
     }
     //	Bust it wide open
     parse_str(Option::server('QUERY_STRING'), $_query);
     //	Set it and forget it
     return !empty($_query) ? array_merge($_query, $_payload) : $_payload;
 }
示例#3
0
 /**
  * Creates a generic, consistent event for scripting and notifications
  *
  * The returned array is as follows:
  *
  * array(
  *  //    Basics
  *  'id'                => 'A unique ID assigned to this event',
  *  'name'              => 'event.name',
  *  'trigger'           => '{api_name}/{resource}',
  *  'stop_propagation'  => [true|false],
  *  'dispatcher'        => array(
  *      'id'            => 'A unique ID assigned to the dispatcher of this event',
  *      'type'          => 'The class name of the dispatcher',
  *  ),
  *  //  Information about the triggering request
  *  'request'           => array(
  *      'timestamp'     => 'timestamp of the initial request',
  *      'path'          => '/full/path/that/triggered/event',
  *      'api_name'      =>'The api_name of the called service',
  *      'resource'      => 'The name of the resource requested',
  *      'body'          => 'The body posted as part of the request (possibly normalized by the service)',
  *  ),
  *  //  Information about the outgoing response.
  *  'response' => 'The response body returned to the calling service and eventually to the requesting client.',
  *  //    Access to the platform api
  *  'platform'      => array(
  *      'api'       => [wormhole to inline-REST API],
  *      'config'    => [standard DSP configuration update],
  *      'session'   => [the current session],
  *  ),
  *  'extra' => [Extra information passed by caller],
  * )
  *
  * Note that this structure is not passed to the script verbatim. Portions are extracted and exposed by the
  * Script resource as it sees fit.
  *
  * Please note that the format of the request and response bodies may differ slightly from the format passed in or
  * sent back to the client. Some service handlers normalize the data for convenience, i.e. see
  * BaseDbSvc::_determineRequestMembers().
  *
  * Therefore the data exposed by the event system has been "normalized" to provide a reliable and consistent manner
  * in which to process said data. There should be no need for wasting time trying to determine if your data is
  * "maybe here, or maybe there, or maybe over there even" when received by your event handlers.
  *
  *
  * @param string          $eventName        The event name
  * @param PlatformEvent   $event            The event
  * @param EventDispatcher $dispatcher       The dispatcher of the event
  * @param array           $extra            Any additional data to put into the event structure
  * @param bool            $includeDspConfig If true, the current DSP config is added to container
  * @param bool            $returnJson       If true, the event will be returned as a JSON string, otherwise an
  *                                          array.
  *
  * @return array|string
  */
 public static function normalizeEvent($eventName, PlatformEvent $event, $dispatcher, array $extra = [], $includeDspConfig = true, $returnJson = false)
 {
     static $config = null;
     if (!$config) {
         $config = $includeDspConfig ? \Cache::get(Config::LAST_RESPONSE_CACHE_KEY, false) : false;
     }
     //	Clean up the event extras, remove data portion
     $eventExtras = $event->getData();
     $path = $dispatcher->getPathInfo(true);
     //	Clean up the trigger
     $trigger = false !== strpos($path, 'rest', 0) || false !== strpos($path, '/rest', 0) ? str_replace(['/rest', 'rest'], null, $path) : $path;
     $request = static::buildRequestArray($event);
     $response = $event->getResponseData();
     //	Build the array
     $event = ['id' => $event->getEventId(), 'name' => $eventName, 'timestamp' => date('c', Option::server('REQUEST_TIME_FLOAT', Option::server('REQUEST_TIME', microtime(true)))), 'trigger' => $trigger, 'request_path' => $path, 'stop_propagation' => ArrayUtils::get($eventExtras, 'stop_propagation', false, true), 'dispatcher_id' => spl_object_hash($dispatcher), 'dispatcher_type' => Inflector::neutralize(get_class($dispatcher)), 'extra' => $extra, 'platform' => ['config' => $config, 'session' => static::getCleanedSession()], 'request' => $request, 'response' => $response];
     return $returnJson ? json_encode($event, JSON_UNESCAPED_SLASHES) : $event;
 }