Beispiel #1
0
 /**
  * Save off the data to the file system
  */
 public function __destruct()
 {
     //	Sync or swim
     Oasys::sync();
     $this->sync();
     parent::__destruct();
 }
Beispiel #2
0
 /**
  * @covers \DreamFactory\Oasys\Oasys::getProvider
  */
 public function testGetProvider()
 {
     //	Good
     $_provider = Oasys::getProvider('google_plus');
     $this->assertInstanceOf('DreamFactory\\Oasys\\Providers\\BaseProvider', $_provider);
     //	Bad
     $this->setExpectedException('\\InvalidArgumentException');
     Oasys::getProvider('woohoo');
 }
Beispiel #3
0
 /**
  * Action for URL that the client redirects to when coming back from providers.
  */
 public function actionRemoteLogin()
 {
     if (null !== $this->_remoteError) {
         $this->_redirectError($this->_remoteError);
     }
     if (null === ($_providerId = Option::request('pid'))) {
         throw new BadRequestException('No remote login provider specified.');
     }
     $this->layout = false;
     $_flow = FilterInput::request('flow', Flows::CLIENT_SIDE, FILTER_SANITIZE_NUMBER_INT);
     //	Check local then global...
     if (null === ($_providerModel = Provider::model()->byPortal($_providerId)->find())) {
         /** @var \stdClass $_providerModel */
         $_providerModel = Fabric::getProviderCredentials($_providerId);
         if (empty($_providerModel)) {
             throw new BadRequestException('The provider "' . $_providerId . '" is not available.');
         }
         //  Translate from back-end to front-end
         $_model = new stdClass();
         $_model->id = $_providerModel->id;
         $_model->provider_name = $_providerModel->provider_name_text;
         $_model->config_text = $_providerModel->config_text;
         $_model->api_name = $_providerModel->endpoint_text;
         $_model->is_active = $_providerModel->enable_ind;
         $_model->is_login_provider = $_providerModel->login_provider_ind;
         $_providerModel = $_model;
     }
     //	Set our store...
     Oasys::setStore($_store = new ProviderUserStore(Session::getCurrentUserId(), $_providerModel->id));
     $_config = Provider::buildConfig($_providerModel, Pii::getState($_providerId . '.user_config', array()), array('flow_type' => $_flow, 'redirect_uri' => Curl::currentUrl(false) . '?pid=' . $_providerModel->provider_name));
     $_provider = Oasys::getProvider($_providerId, $_config);
     if ($_provider->handleRequest()) {
         //	Now let the user model figure out what to do...
         try {
             $_user = User::remoteLoginRequest($_providerId, $_provider, $_providerModel);
             Log::debug('Remote login success: ' . $_user->email . ' (id#' . $_user->id . ')');
         } catch (\Exception $_ex) {
             Log::error($_ex->getMessage());
             //	No soup for you!
             $this->_redirectError($_ex->getMessage());
         }
         //	Go home baby!
         $this->redirect('/');
     }
     Log::error('Seems that the provider rejected the login...');
     $this->_redirectError('Error during remote login sequence. Please try again.');
 }
Beispiel #4
0
 /**
  * @param string $providerId
  *
  * @return array
  */
 public static function getTemplate($providerId)
 {
     /** @var array $_defaults */
     $_defaults = array();
     foreach (Oasys::getProviderPaths() as $_path) {
         //	See if there is a default template and load up the defaults
         $_template = $_path . '/Templates/' . $providerId . '.template.php';
         if (!is_file($_template)) {
             $_template = $_path . '/Templates/' . Inflector::neutralize($providerId) . '.template.php';
         }
         if (is_file($_template) && is_readable($_template)) {
             /** @noinspection PhpIncludeInspection */
             $_defaults = (require $_template);
             break;
         }
     }
     return $_defaults;
 }
 /**
  * Merges any configuration schema with model data
  *
  * @param string $providerId The API name of the provider
  * @param array  $configData
  *
  * @return array|null
  */
 protected function _loadConfigSchema($providerId, $configData = array())
 {
     $_schema = null;
     switch ($providerId) {
         case 'provider':
             /** @var Provider $model */
             $_schema = Oasys::getProvider($providerId)->getConfig()->getSchema();
             break;
     }
     //	Merge
     if (!empty($_schema)) {
         $_config = !empty($configData) ? $configData : array();
         //	Load the resource into the schema for a goof
         foreach ($_schema as $_key => $_value) {
             if (null !== ($_configValue = Option::get($_config, $_key))) {
                 if (is_array($_configValue)) {
                     $_configValue = implode(', ', $_configValue);
                 }
                 $_value['value'] = $_configValue;
             }
             $_schema[static::SCHEMA_PREFIX . $_key] = $_value;
             unset($_schema[$_key]);
         }
     }
     return $_schema;
 }
Beispiel #6
0
 /**
  * Makes a list of available templates
  *
  * @param string $pattern
  *
  * @return void
  */
 protected static function _loadTemplates($pattern = self::DEFAULT_TEMPLATE_PATTERN)
 {
     if (array() !== (static::$_templateCache = Oasys::getStore()->get('oasys.template_cache', array()))) {
         //	Loaded from cache...
         return;
     }
     $_list = array();
     foreach (static::$_providerPaths as $_path) {
         $_templates = glob($_path . '/Templates/' . $pattern);
         foreach ($_templates as $_template) {
             $_templateName = str_ireplace('.template.php', null, basename($_template));
             $_templateId = Inflector::neutralize($_templateName);
             //	Skip base classes in these directories...
             if ('base_' == substr($_templateId, 0, 4)) {
                 continue;
             }
             $_list[$_templateId] = $_path . '/Templates/' . $_template;
             unset($_template, $_templateId, $_templateName);
         }
         unset($_path, $_templates);
     }
     //	Merge in the found templates
     Oasys::getStore()->set('oasys.template_cache', static::$_templateCache = array_merge(static::$_templateCache, $_list));
     Log::debug('Cached templates: ' . implode(', ', array_keys(static::$_templateCache)));
 }
Beispiel #7
0
 /**
  * @return \DreamFactory\Oasys\Interfaces\StorageProviderLike
  */
 public function getStore()
 {
     return Oasys::getStore();
 }
Beispiel #8
0
 /**
  * Retrieves the users' profile from the provider and stores it
  */
 protected function _updateUserProfile()
 {
     $_profile = $this->getUserData();
     if (!empty($_profile)) {
         //	For us...
         $_profile->setProviderId($this->_providerId);
         $this->setConfig('provider_user_id', $_id = $_profile->getUserId());
         //	For posterity - Check if method exists so testing works.
         /** @noinspection PhpUndefinedMethodInspection */
         if (method_exists(Oasys::getStore(), 'setProviderUserId')) {
             Oasys::getStore()->setProviderUserId($_id);
         }
         //	A tag
         Log::debug('User profile updated [' . $this->_providerId . ':' . $_id . ']');
     }
 }
Beispiel #9
0
//$_providerId = 'facebook';
//$_providerId = 'github';
//$_providerId = 'twitter';
$_providerId = 'google_plus';
switch ($_providerId) {
    case 'facebook':
        $_config = array('flow_type' => Flows::CLIENT_SIDE, 'client_id' => FACEBOOK_CLIENT_ID, 'client_secret' => FACEBOOK_CLIENT_SECRET);
        break;
    case 'github':
        $_config = array('flow_type' => Flows::CLIENT_SIDE, 'client_id' => GITHUB_CLIENT_ID, 'client_secret' => GITHUB_CLIENT_SECRET);
        break;
    case 'google_plus':
        $_config = array('flow_type' => Flows::CLIENT_SIDE, 'client_id' => GOOGLE_CLIENT_ID, 'client_secret' => GOOGLE_CLIENT_SECRET);
        break;
    case 'twitter':
        array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET);
        break;
    default:
        throw new OasysException('Provider "' . $_providerId . '" not set supported here.');
        break;
}
//	Start it up
Oasys::setStore(new FileSystem(__FILE__));
$_provider = Oasys::getProvider($_providerId, $_config);
if ($_provider->handleRequest()) {
    /** @var GenericUser $_profile */
    $_profile = $_provider->getUserData();
    header('Content-Type: application/json');
    echo print_r($_profile, true);
    die;
}