/** * Get the session key between an application and the API server. * * @param unknown_type $api_key * @param unknown_type $secret_key * @param RingsideSocialSession $socialSession * @return string session key for the API container */ public static function getApiSessionKey($api_key, $secret_key, RingsideSocialSession $socialSession) { $uid = $socialSession->getUserId(); $sessionKey = $socialSession->getApiSessionKey($api_key); if ($sessionKey != null) { // Validate Session Key is still valid. $apiClient = new RingsideApiClientsRest($api_key, $secret_key, $sessionKey); $apiClient->setNetworkKey($socialSession->getNetwork()); try { $apiClient->users_getLoggedInUser(); } catch (Exception $e) { // error_log( "Session expired? " . $e->getMessage() ) ; // error_log($e->getTraceAsString()); $sessionKey = null; $socialSession->unsetApiSessionKey($api_key); } } if ($sessionKey == null && $uid != null) { // Need to simulate being app and auth, approve, get... which of course // TODO we need to re-think once we are working. // TODO catch some exceptions. try { // Configure where we get the URL for the REST SERVER from. $apiClient = new RingsideApiClientsRest($api_key, $secret_key, null, null, RingsideSocialConfig::$apiKey); // Once the client is authenticated with a session, the network key will be associated via the session $apiClient->setNetworkKey($socialSession->getNetwork()); $auth_token = $apiClient->auth_createToken($socialSession->getExpiry() == null ? true : false); $result = $apiClient->auth_approveToken($uid); $result = $apiClient->auth_getSession($auth_token); if (!empty($apiClient->session_key)) { $sessionKey = trim($apiClient->session_key); $socialSession->addApiSessionKey($api_key, $sessionKey); } } catch (Exception $exception) { error_log("Error creating session key " . $exception); } } return $sessionKey; }
/** * Manufacure a Mock token for use with the test. * * @return unknown */ public function getToken() { $uid_ = '100000'; $vid_ = '100001'; $api_key_ = '4333592132647f39255bb066151a2099'; $api_secret_ = 'b37428ff3f4320a7af98b4eb84a4aa99'; $serverUrl = 'http://localhost:8080/restserver.php'; $app_client = new RingsideApiClientsRest($api_key_, $api_secret_, null, $serverUrl); $authToken = $app_client->auth_createToken(); $res = $app_client->auth_approveToken($uid_); $this->assertEquals("1", $res["result"]); $session_ = $app_client->auth_getSession($authToken); $methods = array(); $arguments = array(); $token = $this->getMock('RingsideGadgetToken'); //,$methods,$arguments $token->expects($this->any())->method('getAppClient')->will($this->returnValue($app_client)); $token->expects($this->any())->method('getAppId')->will($this->returnValue($api_key_)); $token->expects($this->any())->method('getDomain')->will($this->returnValue('ringside')); $token->expects($this->any())->method('getOwnerId')->will($this->returnValue($uid_)); $token->expects($this->any())->method('getViewerId')->will($this->returnValue($vid_)); $token->expects($this->any())->method('getAppUrl')->will($this->returnValue('http://localhost:8080/canvas.php/footprints')); $token->expects($this->any())->method('getModuleId')->will($this->returnValue('footprints')); return $token; }
/** * Finalize the mapping process, this ties a user on a network to a Principal id for that user. * This is typically the endpoint of a given login request on a third party social network. * The method bindmap must have been called first since that setups the request to a login request on a * foreign social network. * * @param array $params */ private static function finalizemap(&$params) { error_log("Finalizing map with parameters: " . var_export($params, true)); $next = isset($params['next']) ? $params['next'] : null; $nid = isset($params['nid']) ? $params['nid'] : null; $sid = isset($params['sid']) ? $params['sid'] : null; $snid = isset($params['snid']) ? $params['snid'] : null; $api_key = isset($params['api_key']) ? $params['api_key'] : null; $sig = isset($params['sig']) ? $params['sig'] : null; $canvas = isset($params['canvas']) ? true : false; $network = isset($params['network']) ? true : false; $iframe = isset($params['fb_sig_in_iframe']) ? $params['fb_sig_in_iframe'] == '1' ? true : false : false; $auth_token = isset($params['auth_token']) ? $params['auth_token'] : null; try { // Get some information about the calling application and registered networks. error_log("Finalizing map from {$snid} to {$nid}"); $ringside_rest = RingsideSocialUtils::getAdminClient($snid); $deployed_app = $ringside_rest->admin_getAppProperties(array('application_id', 'api_key', 'secret_key', 'canvas_url', 'callback_url'), null, null, $api_key, $snid); $trust_info = $ringside_rest->admin_getTrustInfo(array($snid, $nid)); $network_app_props = $ringside_rest->admin_getAppKeys(null, null, $deployed_app['api_key'], $snid); $host_network = $trust_info[0]; $auth_network = $trust_info[1]; $network_api_key = $deployed_app['api_key']; $network_secret = $deployed_app['secret_key']; self::getApiKeyAndSecretForNetwork($auth_network['trust_key'], $network_app_props, $network_api_key, $network_secret); // validate against social network this auth token and get registered user error_log("For auth network {$auth_network['trust_key']}, API key is {$network_api_key} and secret is {$network_secret}"); $auth_network_rest = new RingsideApiClientsRest($network_api_key, $network_secret); $auth_network_rest->setDefaultServer($auth_network['trust_auth_url'], null); $auth_user_info = $auth_network_rest->auth_getSession($auth_token); $auth_user = $auth_user_info['uid']; // if a profile was not created relative to that network, you need to 'create' profile first. $pid = null; if ($auth_user != null) { // We have successfully authenticated the user against the remote network... error_log(var_export($deployed_app, true)); $ringside_rest->admin_mapUser($auth_user, $nid, $sid, $snid, $deployed_app['application_id']); } // Map the USER // OK we mapped redirect user. self::postMapRedirect($next, $canvas, $iframe, $network, $host_network, $deployed_app); } catch (Exception $e) { error_log("Error: When finalizing the mapping: " . $e->getMessage()); error_log($e->getTraceAsString()); echo "Exception when finalizing the UID mapping, " . $e->getMessage(); } return; }
/** * Enter description here... * * @param unknown_type $apiKey * @param unknown_type $secretKey * @param unknown_type $session * @param unknown_type $url * @param unknown_type $uid * @return unknown */ public function getRingsideRestClient($apiKey, $secretKey, $session, $url, $uid) { $apiClientSocial = new RingsideApiClientsRest($apiKey, $secretKey, null, null); $authToken = $apiClientSocial->auth_createToken(); $res = $apiClientSocial->auth_approveToken($uid); $result = $apiClientSocial->auth_getSession($authToken); if ($res["result"] == '1') { return $apiClientSocial; } return null; }