Example #1
0
 /**
  * Loads the configured providers.
  */
 private function _loadProviders()
 {
     if ($this->_providersLoaded) {
         return;
     }
     // providers
     foreach ($this->getProviderSources() as $providerSource) {
         $lcHandle = strtolower($providerSource->getHandle());
         $record = $this->_getProviderRecordByHandle($providerSource->getHandle());
         $provider = Oauth_ProviderModel::populateModel($record);
         $provider->class = $providerSource->getHandle();
         // source
         if ($record && !empty($provider->clientId)) {
             // client id and secret
             $clientId = false;
             $clientSecret = false;
             // ...from config
             $oauthConfig = craft()->config->get('oauth');
             if ($oauthConfig) {
                 if (!empty($oauthConfig[$providerSource->getHandle()]['clientId'])) {
                     $clientId = $oauthConfig[$providerSource->getHandle()]['clientId'];
                 }
                 if (!empty($oauthConfig[$providerSource->getHandle()]['clientSecret'])) {
                     $clientSecret = $oauthConfig[$providerSource->getHandle()]['clientSecret'];
                 }
             }
             // ...from provider
             if (!$clientId) {
                 $clientId = $provider->clientId;
             }
             if (!$clientSecret) {
                 $clientSecret = $provider->clientSecret;
             }
             // source
             $providerSource->initProviderSource($clientId, $clientSecret);
             $provider->setSource($providerSource);
             $this->_configuredProviders[$lcHandle] = $provider;
         } else {
             $provider->setSource($providerSource);
         }
         $this->_allProviders[$lcHandle] = $provider;
     }
     $this->_providersLoaded = true;
 }
 /**
  * Loads the configured providers.
  */
 private function _loadProviders()
 {
     Craft::log(__METHOD__, LogLevel::Info, true);
     if ($this->_providersLoaded) {
         return;
     }
     // providerSources
     $providerSources = array();
     $providersPath = CRAFT_PLUGINS_PATH . 'oauth/providers/';
     $providersFolderContents = IOHelper::getFolderContents($providersPath, false);
     if ($providersFolderContents) {
         foreach ($providersFolderContents as $path) {
             $path = IOHelper::normalizePathSeparators($path);
             $fileName = IOHelper::getFileName($path, false);
             if ($fileName == 'BaseOAuthProviderSource') {
                 continue;
             }
             // Chop off the "OAuthProviderSource" suffix
             $handle = substr($fileName, 0, strlen($fileName) - 19);
             $providerSource = $this->getProviderSource($handle);
             array_push($providerSources, $providerSource);
         }
     }
     // providers
     foreach ($providerSources as $providerSource) {
         $lcHandle = strtolower($providerSource->getHandle());
         $record = $this->_getProviderRecordByHandle($providerSource->getHandle());
         $provider = Oauth_ProviderModel::populateModel($record);
         $provider->class = $providerSource->getHandle();
         if ($record && !empty($provider->clientId)) {
             $providerSource->setClient($provider->clientId, $provider->clientSecret);
             $provider->providerSource = $providerSource;
             $this->_configuredProviders[$lcHandle] = $provider;
         } else {
             $provider->providerSource = $providerSource;
         }
         $this->_allProviders[$lcHandle] = $provider;
     }
     $this->_providersLoaded = true;
 }