/** * 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; }
/** * 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; }