/** * Authenticates a user using oauth_token,oauth_secret * * * @param array $credentials Array holding the user credentials * @param array $options Array of extra options * @param object $response Authentication response object * @return boolean * @since 1.5 */ public function onAuthenticate(&$credentials, $options, &$response) { if (isset($credentials['username']) && isset($credentials['password'])) { return; } if (isset($credentials['oauth_token']) && isset($credentials['oauth_handler'])) { try { extract($credentials, EXTR_SKIP); //if oatuh secret not set then set it to null if (empty($oauth_secret)) { $oauth_secret = ''; } //lets get the api $api = ComConnectHelperApi::getApi($oauth_handler); $api->setToken($oauth_token, $oauth_secret); //if we can get the logged in user then //the user is authenticated if ($profile_id = $api->getUser()->id) { //lets find a valid sesison //lets be strict and make sure all the values match $session = KService::get('repos://site/connect.session')->find(array('owner.type' => 'com:people.domain.entity.person', 'profileId' => $profile_id, 'tokenKey' => $oauth_token, 'api' => $oauth_handler)); if ($session) { $response->status = JAUTHENTICATE_STATUS_SUCCESS; $response->username = $session->owner->username; $response->password = '******'; $response->fullname = ' '; } } } catch (Exception $e) { //ignore any exception } } }
/** * Return an instance of API Adapter. * * @return ComConnectOauthApiAbstract */ public function getApi() { if (!isset($this->_api)) { $this->_api = ComConnectHelperApi::getApi($this->get('api')); $this->_api->setToken($this->tokenKey, $this->tokenSecret); } return $this->_api; }
/** * Render logins, If $return_array is set to true, then it returns an array instead of a string * * @param boolean $return_array Boolean value to whether return an array of string or one string. By default is false * @return string */ public function renderLogins($return_array = false) { $services = ComConnectHelperApi::getServices(); $html = array(); foreach ($services as $name => $service) { $html[] = $this->login($name); } return $return_array ? $html : implode(' ', $html); }
/** * {@inheritdoc} */ public function onSettingDisplay(KEvent $event) { $actor = $event->actor; $tabs = $event->tabs; $services = ComConnectHelperApi::getServices(); if (count($services)) { $tabs->insert('connect', array('label' => JText::_('COM-CONNECT-PROFILE-EDIT'), 'controller' => 'com://site/connect.controller.setting')); } }
/** * Get action. * * Renders the actor setting for connect * * @param KCommandContext $context Context parameter * @param void */ protected function _actionRead(KCommandContext $context) { $apis = ComConnectHelperApi::getServices(); $this->getService('repos:connect.session'); $sessions = $this->actor->sessions; foreach ($apis as $key => $api) { if (!$api->canAddService($this->actor)) { unset($apis[$key]); } } $this->apis = $apis; $this->sessions = $sessions; }
/** * Before _actionGet controller event. * * @param KEvent $event Event object * * @return string */ public function onBeforeControllerGet(KEvent $event) { $this->setActor(get_viewer()); parent::onBeforeControllerGet($event); $data = $event->data; $viewer = get_viewer(); $actor = $viewer; $layout = pick($this->getController()->layout, 'default'); $name = $this->getController()->getIdentifier()->name; if ($name == 'connection') { $name = $this->getController()->service; } $this->setTitle(JText::sprintf('COM-INVITES-ACTOR-HEADER-' . strtoupper($name) . 'S', $actor->name)); //create navigations $this->addNavigation('email', JText::_('COM-INVITES-LINK-EMAIL'), 'option=com_invites&view=email', $name == 'email'); if (ComConnectHelperApi::enabled('facebook')) { $this->addNavigation('facebook', JText::_('COM-INVITES-LINK-FACEBOOK'), 'option=com_invites&view=connections&service=facebook', $name == 'facebook'); } }
/** * Context. * * @param KCommandContext $context */ protected function _actionBrowse(KCommandContext $context) { $serviceType = pick($this->service, 'facebook'); if (!ComConnectHelperApi::enabled($serviceType)) { throw new LibBaseControllerExceptionBadRequest('Service is not enabled'); return; } $this->getService('repos://site/connect.session'); $service = $this->viewer->sessions->{$serviceType}; if (!empty($service)) { try { $this->_state->setList($service->getFriends()); } catch (Exception $e) { $session = $this->viewer->sessions->find(array('api' => 'facebook')); if (isset($session)) { $session->delete()->save(); } $service = null; } } else { $service = null; } $this->service = $service; }
/** * Modify session query to only bring the sessions that are available * * @return void */ protected function _beforeRepositoryFetch(KCommandContext $context) { $query = $context->query; $services = array_keys(ComConnectHelperApi::getServices()); $query->api($services); }
/** * Returns if a service is enabled * * @param string $service Service name * * @return bool */ public static function enabled($service) { $service = strtolower($service); return get_config_value('connect.' . $service . '_enable', true) && ComConnectHelperApi::getConsumer($service)->isValid(); }
/** * Creates an api object either from the session or the values in the post. */ protected function _getApi() { $post = KRequest::get('post', 'string'); $api = null; try { if (isset($post['oauth_token']) && isset($post['oauth_handler'])) { $api = ComConnectHelperApi::getApi($post['oauth_handler']); $api->setToken($post['oauth_token'], isset($post['oauth_secret']) ? $post['oauth_secret'] : ''); } else { $session = new KConfig(KRequest::get('session.oauth', 'raw', array())); if (!$session->token || !$session->api || !$session->consumer) { return; } KRequest::set('session.oauth', null); KService::get('koowa:loader')->loadIdentifier('com://site/connect.oauth.consumer'); $api = KService::get('com://site/connect.oauth.service.' . $session->api, array('consumer' => new ComConnectOauthConsumer($session->consumer), 'token' => $session->token)); } } catch (Exception $e) { $api = null; } return $api; }
</div> </div> <?php } ?> <div class="clearfix"> <span class="connect"> <?php $app = @service('repos://site/components.component')->find(array('component' => 'com_connect')); ?> <?php if ($app && $app->authorize('echo', array('actor' => $actor))) { ?> <?php $services = ComConnectHelperApi::getServices(); @service('repos://site/connect.session'); $sessions = $actor->sessions->toArray(); foreach ($sessions as $key => $session) { if ($session->getApi()->isReadOnly()) { unset($sessions[$key]); } } ?> <?php if (count($sessions) > 0) { ?> <?php foreach ($sessions as $session) { ?>