Exemplo n.º 1
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');
 }
Exemplo n.º 2
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.');
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
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;
}